mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
feat(build-dir): Added validation for unmatched brackets in template
This commit is contained in:
parent
2a11c26af2
commit
ad3e593e53
@ -687,6 +687,16 @@ impl GlobalContext {
|
||||
} => anyhow!(
|
||||
"unexpected variable `{variable}` in build.build-dir path `{raw_template}`"
|
||||
),
|
||||
path::ResolveTemplateError::UnexpectedBracket { bracket_type, raw_template } => {
|
||||
let (btype, literal) = match bracket_type {
|
||||
path::BracketType::Opening => ("opening", "{"),
|
||||
path::BracketType::Closing => ("closing", "}"),
|
||||
};
|
||||
|
||||
anyhow!(
|
||||
"unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`"
|
||||
)
|
||||
}
|
||||
})?;
|
||||
|
||||
// Check if the target directory is set to an empty string in the config.toml file.
|
||||
|
@ -58,6 +58,20 @@ impl ConfigRelativePath {
|
||||
});
|
||||
};
|
||||
|
||||
if value.contains("{") {
|
||||
return Err(ResolveTemplateError::UnexpectedBracket {
|
||||
bracket_type: BracketType::Opening,
|
||||
raw_template: self.0.val.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
if value.contains("}") {
|
||||
return Err(ResolveTemplateError::UnexpectedBracket {
|
||||
bracket_type: BracketType::Closing,
|
||||
raw_template: self.0.val.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(self.0.definition.root(gctx).join(&value))
|
||||
}
|
||||
|
||||
@ -139,4 +153,14 @@ pub enum ResolveTemplateError {
|
||||
variable: String,
|
||||
raw_template: String,
|
||||
},
|
||||
UnexpectedBracket {
|
||||
bracket_type: BracketType,
|
||||
raw_template: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BracketType {
|
||||
Opening,
|
||||
Closing,
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ fn template_workspace_path_hash_should_handle_symlink() {
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn template_should_handle_ignore_unmatched_brackets() {
|
||||
fn template_should_handle_reject_unmatched_brackets() {
|
||||
let p = project()
|
||||
.file("src/lib.rs", "")
|
||||
.file(
|
||||
@ -699,6 +699,11 @@ fn template_should_handle_ignore_unmatched_brackets() {
|
||||
|
||||
p.cargo("build -Z build-dir")
|
||||
.masquerade_as_nightly_cargo(&["build-dir"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] unexpected opening bracket `{` in build.build-dir path `foo/{bar`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
let p = project()
|
||||
@ -714,6 +719,11 @@ fn template_should_handle_ignore_unmatched_brackets() {
|
||||
|
||||
p.cargo("build -Z build-dir")
|
||||
.masquerade_as_nightly_cargo(&["build-dir"])
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] unexpected closing bracket `}` in build.build-dir path `foo/}bar`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user