From 57fff7e032b0d048f9fb274d3fc9761e2ca92754 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 8 Aug 2025 10:32:50 +0200 Subject: [PATCH] unlink: fix handling of non-UTF-8 filenames --- tests/by-util/test_unlink.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 905f579a6..002a5929c 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -75,3 +75,31 @@ fn test_unlink_symlink() { assert!(at.file_exists("foo")); assert!(!at.file_exists("bar")); } + +#[test] +#[cfg(target_os = "linux")] +fn test_unlink_non_utf8_paths() { + use std::ffi::OsStr; + use std::os::unix::ffi::OsStrExt; + use uutests::util::TestScenario; + use uutests::util_name; + + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + // Create a test file with non-UTF-8 bytes in the name + let non_utf8_bytes = b"test_\xFF\xFE.txt"; + let non_utf8_name = OsStr::from_bytes(non_utf8_bytes); + + // Create the actual file + at.touch(non_utf8_name); + assert!(at.file_exists(non_utf8_name)); + + // Test that unlink handles non-UTF-8 file names without crashing + scene.ucmd() + .arg(non_utf8_name) + .succeeds(); + + // The file should be removed + assert!(!at.file_exists(non_utf8_name)); +}