Skip to content

Commit 6e0afc3

Browse files
committed
fix: path separator on windows
1 parent 87f649a commit 6e0afc3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/fmt/json.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::os::unix::{ffi::OsStrExt, fs::MetadataExt};
66
use std::path::{MAIN_SEPARATOR, Path};
77
use std::time::SystemTime;
88

9+
#[cfg(unix)]
910
use base64::{Engine as _, prelude::BASE64_STANDARD};
1011
use 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 {

0 commit comments

Comments
 (0)