Merge pull request #7 from JDepooter/handle_crlf_input

Handle carriage returns in source JSON whitespace
This commit is contained in:
nora 2025-03-21 18:19:47 +01:00 committed by GitHub
commit d81777b8a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,7 +88,7 @@ where
match char {
b'"' => in_string = true,
b' ' | b'\n' | b'\t' => continue,
b' ' | b'\n' | b'\r' | b'\t' => continue,
b'[' => {
indent_level += 1;
request_newline = true;
@ -245,4 +245,21 @@ mod test {
assert_eq!(expected, format(expected, Indentation::TwoSpace));
}
#[test]
fn contains_crlf() {
let json = "[\r\n{\r\n\"a\":0\r\n},\r\n{},\r\n{\r\n\"a\": null\r\n}\r\n]\r\n";
let expected = "[
{
\"a\": 0
},
{},
{
\"a\": null
}
]
";
assert_eq!(expected, format(json, Indentation::TwoSpace));
}
}