Skip to content

Commit

Permalink
fix: sanitise_name: Don't consider punctuation and control chars as p…
Browse files Browse the repository at this point in the history
…art of file extension (#6362)
  • Loading branch information
iequidoo committed Dec 24, 2024
1 parent 5772284 commit 64a1b8e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ impl<'a> BlobObject<'a> {
let ext: String = name
.chars()
.rev()
.take_while(|c| !c.is_whitespace())
.take_while(|c| {
(!c.is_ascii_punctuation() || *c == '.') && !c.is_whitespace() && !c.is_control()
})
.take(33)
.collect::<Vec<_>>()
.iter()
Expand Down Expand Up @@ -982,6 +984,10 @@ mod tests {
let (stem, ext) = BlobObject::sanitise_name("a. tar.tar.gz");
assert_eq!(stem, "a. tar");
assert_eq!(ext, ".tar.gz");

let (stem, ext) = BlobObject::sanitise_name("Guia_uso_GNB (v0.8).pdf");
assert_eq!(stem, "Guia_uso_GNB (v0.8)");
assert_eq!(ext, ".pdf");
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down

0 comments on commit 64a1b8e

Please sign in to comment.