File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use std::os::unix::{ffi::OsStrExt, fs::MetadataExt};
66use std:: path:: { MAIN_SEPARATOR , Path } ;
77use std:: time:: SystemTime ;
88
9+ #[ cfg( unix) ]
910use base64:: { Engine as _, prelude:: BASE64_STANDARD } ;
1011use jiff:: Timestamp ;
1112
@@ -39,12 +40,19 @@ pub fn output_json<W: Write>(
3940 write ! ( out, r#""path":{{"bytes":"{}"}}"# , encoded_bytes) ?;
4041 }
4142 } ;
43+
4244 // On non-unix platforms, if the path isn't valid utf-8,
4345 // we don't know what kind of encoding was used, and
4446 // as_encoded_bytes() isn't necessarily stable between rust versions
4547 // so the best we can really do is a lossy string
4648 #[ cfg( not( unix) ) ]
47- write ! ( out, r#""path":{{"text":{:?}}}"# , path. to_string_lossy( ) ) ?;
49+ {
50+ let mut path = path. to_string_lossy ( ) ;
51+ if let Some ( sep) = path_separator {
52+ path = path. replace ( MAIN_SEPARATOR , sep) . into ( ) ;
53+ }
54+ write ! ( out, r#""path":{{"text":{:?}}}"# , path) ?;
55+ }
4856
4957 // print the type of file
5058 let ft = match filetype {
You can’t perform that action at this time.
0 commit comments