From 64a1b8e57ce315d12d2d7996bb642a4cd9c5fa78 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Mon, 23 Dec 2024 15:16:13 -0300 Subject: [PATCH] fix: sanitise_name: Don't consider punctuation and control chars as part of file extension (#6362) --- src/blob.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/blob.rs b/src/blob.rs index 63c2350562..403c8ea6ca 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -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::>() .iter() @@ -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)]