File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,8 @@ impl<'a> Display for PathQuotedDisplay<'a> {
1818 }
1919 }
2020 if let Ok ( r) = shlex:: bytes:: try_quote ( self . path . as_os_str ( ) . as_bytes ( ) ) {
21- if let Ok ( s) = std:: str:: from_utf8 ( & r) {
22- return f. write_str ( s) ;
23- }
21+ let s = String :: from_utf8_lossy ( & r) ;
22+ return f. write_str ( & s) ;
2423 }
2524 // Should not happen really
2625 return Err ( std:: fmt:: Error ) ;
@@ -40,6 +39,8 @@ impl<'a> PathQuotedDisplay<'a> {
4039
4140#[ cfg( test) ]
4241mod tests {
42+ use std:: ffi:: OsStr ;
43+
4344 use super :: * ;
4445
4546 #[ test]
@@ -61,4 +62,12 @@ mod tests {
6162 assert_eq ! ( quoted, format!( "{}" , PathQuotedDisplay :: new( & v) ) ) ;
6263 }
6364 }
65+
66+ #[ test]
67+ fn test_nonutf8 ( ) {
68+ let p = Path :: new ( OsStr :: from_bytes ( b"/foo/somenonutf8\xEE /bar" ) ) ;
69+ assert ! ( p. to_str( ) . is_none( ) ) ;
70+ let q = PathQuotedDisplay :: new ( & p) . to_string ( ) ;
71+ assert_eq ! ( q, r#"'/foo/somenonutf8�/bar'"# ) ;
72+ }
6473}
You can’t perform that action at this time.
0 commit comments