File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -350,9 +350,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
350350 USimpleError :: new ( 1 , format ! ( "invalid date '{escaped_str}'" ) )
351351 } ) ?;
352352 DateSource :: Human ( date. into ( ) )
353- } else if let Some ( file) = matches. get_one :: < String > ( OPT_FILE ) {
354- match file. as_ref ( ) {
355- "-" => DateSource :: Stdin ,
353+ } else if let Some ( file) = matches. get_one :: < OsString > ( OPT_FILE ) {
354+ match file. as_encoded_bytes ( ) {
355+ b "-" => DateSource :: Stdin ,
356356 _ => DateSource :: File ( file. into ( ) ) ,
357357 }
358358 } else if let Some ( file) = matches. get_one :: < OsString > ( OPT_REFERENCE ) {
@@ -695,6 +695,7 @@ pub fn uu_app() -> Command {
695695 . long ( OPT_FILE )
696696 . value_name ( "DATEFILE" )
697697 . value_hint ( clap:: ValueHint :: FilePath )
698+ . value_parser ( clap:: value_parser!( OsString ) )
698699 . conflicts_with ( OPT_DATE )
699700 . help ( translate ! ( "date-help-file" ) ) ,
700701 )
Original file line number Diff line number Diff line change @@ -642,6 +642,20 @@ fn test_date_for_empty_file() {
642642 ucmd. arg ( "--file" ) . arg ( file) . succeeds ( ) . no_output ( ) ;
643643}
644644
645+ #[ test]
646+ #[ cfg( target_os = "linux" ) ]
647+ #[ cfg_attr( wasi_runner, ignore = "WASI: argv/filenames must be valid UTF-8" ) ]
648+ fn test_date_for_file_with_non_utf8_path ( ) {
649+ use std:: os:: unix:: ffi:: OsStrExt ;
650+
651+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
652+
653+ let file = std:: ffi:: OsStr :: from_bytes ( b"file_\xFF \xFE .txt" ) ;
654+ std:: fs:: File :: create ( at. plus ( file) ) . unwrap ( ) ;
655+
656+ ucmd. arg ( "--file" ) . arg ( file) . succeeds ( ) . no_output ( ) ;
657+ }
658+
645659#[ test]
646660fn test_date_file_invalid_utf8_line ( ) {
647661 let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
You can’t perform that action at this time.
0 commit comments