-
Notifications
You must be signed in to change notification settings - Fork 24
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
Handling dependency name sanitization #127
Conversation
src/utils.rs
Outdated
pub fn sanitize_dependency_name(dependency_name: &str) -> String { | ||
if FILE_NAME_REGEX.is_match(dependency_name) { | ||
return String::new(); | ||
} | ||
dependency_name.replace("/", "-") | ||
} |
There was a problem hiding this comment.
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: "-" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")); |
No description provided.