Skip to content

Commit

Permalink
Fail if a member's path includes invalid components.
Browse files Browse the repository at this point in the history
Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Oct 24, 2023
1 parent 78cfe9b commit ebc1eab
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,17 @@ fn update_manifest_with_new_member(
)
})?;

let display_path = relpath
.iter()
.filter_map(|comp| comp.to_str())
.collect::<Vec<_>>()
.join("/");
let mut components = Vec::new();
for comp in relpath.iter() {
let comp = comp.to_str().with_context(|| {
format!(
"invalid non-ascii component in path `{}`",
relpath.display()
)
})?;
components.push(comp);
}
let display_path = components.join("/");

// Don't add the new package to the workspace's members
// if there is an exclusion match for it.
Expand Down Expand Up @@ -1018,12 +1024,6 @@ fn update_manifest_with_new_member(
let mut array = Array::new();
array.push(&display_path);

// Add a trailing empty line
// if it's a new workspace without any elements already.
if !workspace_document.contains_key("workspace") {
array.decor_mut().set_suffix("\n");
}

workspace_document["workspace"]["members"] = toml_edit::value(array);
}

Expand Down

0 comments on commit ebc1eab

Please sign in to comment.