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> {
18
18
}
19
19
}
20
20
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) ;
24
23
}
25
24
// Should not happen really
26
25
return Err ( std:: fmt:: Error ) ;
@@ -40,6 +39,8 @@ impl<'a> PathQuotedDisplay<'a> {
40
39
41
40
#[ cfg( test) ]
42
41
mod tests {
42
+ use std:: ffi:: OsStr ;
43
+
43
44
use super :: * ;
44
45
45
46
#[ test]
@@ -61,4 +62,12 @@ mod tests {
61
62
assert_eq ! ( quoted, format!( "{}" , PathQuotedDisplay :: new( & v) ) ) ;
62
63
}
63
64
}
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
+ }
64
73
}
You can’t perform that action at this time.
0 commit comments