Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling dependency name sanitization #127

Conversation

mario-eth
Copy link
Owner

No description provided.

src/utils.rs Outdated
Comment on lines 151 to 156
pub fn sanitize_dependency_name(dependency_name: &str) -> String {
if FILE_NAME_REGEX.is_match(dependency_name) {
return String::new();
}
dependency_name.replace("/", "-")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit simplistic, and we could avoid to error if we instead replace the offending characters by allowed ones.
Maybe we can use https://crates.io/crates/sanitize-filename instead of rolling our own. They handle windows special chars and max file length too.

src/utils.rs Outdated
@@ -145,18 +145,50 @@ pub fn get_url_type(dependency_url: &str) -> UrlType {
UrlType::Http
}

pub fn sanitize_dependency_name(dependency_name: &str) -> String {
let options = sanitize_filename::Options { truncate: true, windows: true, replacement: "-" };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let options = sanitize_filename::Options { truncate: true, windows: true, replacement: "-" };
let options = sanitize_filename::Options { truncate: true, windows: cfg!(windows), replacement: "-" };

src/config.rs Outdated
let new_dep_remapped = format_remap_name(soldeer_config, add_dep);
let new_dep_orig =
format!("dependencies/{}-{}/", add_dep.name(), add_dep.version());
let new_dep_remapped: String = format_remap_name(soldeer_config, add_dep);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let new_dep_remapped: String = format_remap_name(soldeer_config, add_dep);
let new_dep_remapped = format_remap_name(soldeer_config, add_dep);

src/janitor.rs Outdated
let sanitized_name =
sanitize_dependency_name(&format!("{}-{}", dependency.name(), dependency.version()));

let new_path: std::path::PathBuf = DEPENDENCY_DIR.clone().join(format!("{sanitized_name}.zip"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let new_path: std::path::PathBuf = DEPENDENCY_DIR.clone().join(format!("{sanitized_name}.zip"));
let new_path = DEPENDENCY_DIR.clone().join(format!("{sanitized_name}.zip"));

@mario-eth mario-eth merged commit 1993de3 into main Aug 6, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants