Skip to content

Commit

Permalink
feat(sanitize): replace each offending character
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Feb 14, 2025
1 parent 13449f1 commit cb2693e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions edu-sync/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl PathBufExt for PathBuf {
pub fn sanitize_path_component(path_component: &str) -> Cow<'_, str> {
static RE: OnceLock<Regex> = OnceLock::new();

RE.get_or_init(|| Regex::new(r"[\\/]+|^\.\.??$").unwrap())
RE.get_or_init(|| Regex::new(r"[\\/]|^\.\.??$").unwrap())
.replace_all(path_component, NoExpand("_"))
}

Expand All @@ -85,7 +85,7 @@ mod tests {

#[test]
fn sanitize_filename_test() {
assert_eq!(sanitize_path_component(r"/a//b/\c\\d\"), "_a_b_c_d_");
assert_eq!(sanitize_path_component(r"/a//b/\c\\d\"), "_a__b__c__d_");
assert_eq!(sanitize_path_component(".a.b."), ".a.b.");
assert_eq!(sanitize_path_component("."), "_");
assert_eq!(sanitize_path_component(".."), "_");
Expand Down

0 comments on commit cb2693e

Please sign in to comment.