mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
unlink: fix handling of non-UTF-8 filenames
This commit is contained in:
parent
a0f1e34d10
commit
57fff7e032
1 changed files with 28 additions and 0 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue