fix(snix/store/import): don't unsafely construct OsStr
What we're doing is safe on POSIX, but not elsewhere, so we should use the Unix-only safe OsStr::from_bytes method rather than adding unsafety. Change-Id: Ib53edaec77a1a0aa2663287d973d398274fde79a Reviewed-on: https://cl.snix.dev/c/snix/+/30263 Tested-by: besadii Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
parent
1859e517da
commit
7a2e70062c
1 changed files with 2 additions and 2 deletions
|
|
@ -131,7 +131,7 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{ffi::OsStr, path::PathBuf};
|
||||
use std::{ffi::OsStr, os::unix::ffi::OsStrExt, path::PathBuf};
|
||||
|
||||
use crate::import::path_to_name;
|
||||
use rstest::rstest;
|
||||
|
|
@ -150,7 +150,7 @@ mod tests {
|
|||
#[case::path_ending_in_dotdot(b"a/b/..")]
|
||||
#[case::non_unicode_path(b"\xf8\xa1\xa1\xa1\xa1")]
|
||||
fn test_invalid_path_to_name(#[case] invalid_path: &[u8]) {
|
||||
let path: PathBuf = unsafe { OsStr::from_encoded_bytes_unchecked(invalid_path) }.into();
|
||||
let path: PathBuf = OsStr::from_bytes(invalid_path).into();
|
||||
path_to_name(&path).expect_err("must fail");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue