Fix splitting logic
This commit is contained in:
parent
388b7bfabb
commit
64274f4de5
1 changed files with 22 additions and 1 deletions
|
|
@ -8,5 +8,26 @@ pub fn sanitize_path(path: &str) -> String {
|
||||||
replacement: "",
|
replacement: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
sanitize_filename::sanitize_with_options(path, options)
|
path.split('/')
|
||||||
|
.map(|part| {
|
||||||
|
let proposal = sanitize_filename::sanitize_with_options(part, options.clone());
|
||||||
|
if !part.is_empty() && proposal.is_empty() {
|
||||||
|
"_".to_owned()
|
||||||
|
} else {
|
||||||
|
proposal
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sanitize_path() {
|
||||||
|
assert_eq!(sanitize_path("/my/path/what?"), "/my/path/what");
|
||||||
|
assert_eq!(sanitize_path("/my/path/\\\\:?"), "/my/path/_");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue