From adffd30f13aa0c2b391865c02b901495e5c989bc Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 23 Jul 2025 13:09:51 +0800 Subject: [PATCH] fsext: Add parsing test for non-unicode mount point --- src/uucore/src/lib/features/fsext.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index e1bea1689..345c1bff1 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -1131,4 +1131,35 @@ mod tests { assert_eq!(info.mount_dir, r#"/mnt/f\ oo"#); } + + #[test] + #[cfg(any(target_os = "linux", target_os = "android"))] + fn test_mountinfo_dir_non_unicode() { + let info = MountInfo::new( + LINUX_MOUNTINFO, + &b"317 61 7:0 / /mnt/some-\xc0-dir-\xf3 rw,relatime shared:641 - ext4 /dev/loop0 rw" + .split(|c| *c == b' ') + .collect::>(), + ) + .unwrap(); + + assert_eq!( + info.mount_dir, + crate::os_str_from_bytes(b"/mnt/some-\xc0-dir-\xf3").unwrap() + ); + + let info = MountInfo::new( + LINUX_MOUNTINFO, + &b"317 61 7:0 / /mnt/some-\\040-dir-\xf3 rw,relatime shared:641 - ext4 /dev/loop0 rw" + .split(|c| *c == b' ') + .collect::>(), + ) + .unwrap(); + + // Note that the \040 above will have been substituted by a space. + assert_eq!( + info.mount_dir, + crate::os_str_from_bytes(b"/mnt/some- -dir-\xf3").unwrap() + ); + } }