Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(automation): avoid empty sanitized filename components

Richie McIlroy8de106540705
diff --git a/crates/automation/src/lib.rs b/crates/automation/src/lib.rs
index c9e31114c..e032fb164 100644
--- a/crates/automation/src/lib.rs
+++ b/crates/automation/src/lib.rs
@@ -443,9 +443,12 @@ pub fn sanitize_filename_component(value: &str) -> String {
.collect();
// Windows rejects filenames ending in a space or '.', so trim those after clamping the length.
- sanitized
- .trim_end_matches(|c: char| c == ' ' || c == '.')
- .to_string()
+ let trimmed = sanitized.trim_end_matches(|c: char| c == ' ' || c == '.');
+ if trimmed.is_empty() {
+ "_".to_string()
+ } else {
+ trimmed.to_string()
+ }
}
/// Build a single shell command line from a program and its arguments, quoting each token so that
diff --git a/crates/automation/src/tests.rs b/crates/automation/src/tests.rs
index 22830f5c9..58ab5bbc8 100644
--- a/crates/automation/src/tests.rs
+++ b/crates/automation/src/tests.rs
@@ -789,6 +789,9 @@ fn sanitize_filename_component_neutralizes_traversal_and_reserved_chars() {
.count(),
128
);
+ assert_eq!(sanitize_filename_component("..."), "_");
+ assert_eq!(sanitize_filename_component(" "), "_");
+ assert_eq!(sanitize_filename_component(""), "_");
}
#[test]