diff --git a/src/tests.rs b/src/tests.rs index a322f71..99d04eb 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -29,8 +29,9 @@ mod os_limited { use super::{get_unique_name, init_logging}; use serial_test::serial; use std::collections::{hash_map::Entry, HashMap}; - use std::ffi::OsString; + use std::ffi::{OsStr, OsString}; use std::fs::File; + use std::os::unix::ffi::OsStringExt; use crate as trash; @@ -94,6 +95,22 @@ mod os_limited { let _ = trash::os_limited::purge_all(items.iter().flat_map(|(_name, item)| item)); } + #[test] + #[serial] + fn list_invalid_utf8() { + let mut name = OsStr::new(&get_unique_name()).to_os_string().into_encoded_bytes(); + name.push(168); + let name = OsString::from_vec(name); + File::create(&name).unwrap(); + + // Delete, list, and remove file with an invalid UTF8 name + // Listing items is already exhaustively checked above, so this test is mainly concerned + // with checking that listing non-Unicode names does not panic + trash::delete(&name).unwrap(); + let item = trash::os_limited::list().unwrap().into_iter().find(|item| item.name == name).unwrap(); + let _ = trash::os_limited::purge_all([item]); + } + #[test] fn purge_empty() { init_logging(); diff --git a/tests/trash.rs b/tests/trash.rs index 67f6b01..936c7fc 100644 --- a/tests/trash.rs +++ b/tests/trash.rs @@ -139,6 +139,7 @@ fn create_remove_single_file() { assert!(File::open(&name).is_err()); } +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))] #[test] #[serial] fn create_remove_single_file_invalid_utf8() {