@@ -1291,26 +1291,34 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
12911291 let reader = open_with_open_failed_error ( & files0_from) ?;
12921292 let buf_reader = BufReader :: new ( reader) ;
12931293 for ( line_num, line) in buf_reader. split ( b'\0' ) . flatten ( ) . enumerate ( ) {
1294- let f = std:: str:: from_utf8 ( & line)
1295- . expect ( "Could not parse string from zero terminated input." ) ;
1296- match f {
1297- STDIN_FILE => {
1298- return Err ( SortError :: MinusInStdIn . into ( ) ) ;
1294+ // Handle filenames as raw bytes to support non-UTF-8 paths
1295+ #[ cfg( unix) ]
1296+ let filename = {
1297+ use std:: os:: unix:: ffi:: OsStrExt ;
1298+ OsStr :: from_bytes ( & line) . to_owned ( )
1299+ } ;
1300+ #[ cfg( not( unix) ) ]
1301+ let filename = {
1302+ // On non-Unix systems, convert to UTF-8 with replacement chars
1303+ match std:: str:: from_utf8 ( & line) {
1304+ Ok ( s) => OsString :: from ( s) ,
1305+ Err ( _) => OsString :: from ( String :: from_utf8_lossy ( & line) . into_owned ( ) ) ,
12991306 }
1300- "" => {
1301- return Err ( SortError :: ZeroLengthFileName {
1302- file : files0_from,
1303- line_num : line_num + 1 ,
1304- }
1305- . into ( ) ) ;
1307+ } ;
1308+
1309+ // Check for special cases using bytes comparison
1310+ if line == b"-" {
1311+ return Err ( SortError :: MinusInStdIn . into ( ) ) ;
1312+ }
1313+ if line. is_empty ( ) {
1314+ return Err ( SortError :: ZeroLengthFileName {
1315+ file : files0_from,
1316+ line_num : line_num + 1 ,
13061317 }
1307- _ => { }
1318+ . into ( ) ) ;
13081319 }
13091320
1310- files. push ( OsString :: from (
1311- std:: str:: from_utf8 ( & line)
1312- . expect ( "Could not parse string from zero terminated input." ) ,
1313- ) ) ;
1321+ files. push ( filename) ;
13141322 }
13151323 if files. is_empty ( ) {
13161324 return Err ( SortError :: EmptyInputFile { file : files0_from } . into ( ) ) ;
0 commit comments