Skip to content

Commit be0bc8f

Browse files
Read the full file without line translation
It seems like the length reported by the channel and the one that `really_read` expects do not match when some line ending translation is happening. Thus try to avoid the translation.
1 parent c264027 commit be0bc8f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Fixed handling of escape sequences in JSON5. Known escapes like \b will be
1212
properly unescaped and undefined escape sequences will unescape to the
1313
character itself as per spec (#187, @david-maison-TrustInSoft)
14+
- Fixed tests failing on Windows due to disagreements with the length of an
15+
input channel and the text mode conversion (#192, @Leonidas-from-XIV)
1416

1517
### Removed
1618

test/test_write.ml

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ let to_string_tests =
1616
fun () -> test ~suf:"" Fixtures.json_string );
1717
]
1818

19+
let replace_crlf s =
20+
(* a bit hacky as it will just remove \r even when not \r\n *)
21+
let parts = String.split_on_char '\r' s in
22+
String.concat "" parts
23+
1924
let to_file_tests =
2025
let test ?suf expected =
2126
let output_file = Filename.temp_file "test_yojson_to_file" ".json" in
2227
Yojson.Safe.to_file ?suf output_file Fixtures.json_value;
2328
let file_content =
24-
let ic = open_in output_file in
29+
let ic = open_in_bin output_file in
2530
let length = in_channel_length ic in
2631
let s = really_input_string ic length in
2732
close_in ic;
28-
s
33+
replace_crlf s
2934
in
3035
Sys.remove output_file;
3136
Alcotest.(check string) __LOC__ expected file_content

0 commit comments

Comments
 (0)