@@ -28,23 +28,35 @@ Done.`),
2828 ) . toBe ( '{"message":"literal } brace","nested":{"ok":true}}' ) ;
2929 } ) ;
3030
31- it ( "decodes JSON with comments and trailing commas" , ( ) => {
32- expect (
33- decodeLenientJson ( `{
31+ it . each ( [ "\n" , "\r\n" , "\r" ] ) (
32+ "decodes comments and trailing commas with %j line endings" ,
33+ ( eol ) => {
34+ expect (
35+ decodeLenientJson (
36+ `{
3437 // Comments are valid in settings files.
3538 "enabled": /* See "https://example.com/config" // still in the block */ true,
3639 "values": [1, 2,],
37- }` ) ,
38- ) . toEqual ( {
39- enabled : true ,
40- values : [ 1 , 2 ] ,
41- } ) ;
42- } ) ;
40+ }` . replaceAll ( "\n" , eol ) ,
41+ ) ,
42+ ) . toEqual ( {
43+ enabled : true ,
44+ values : [ 1 , 2 ] ,
45+ } ) ;
46+ } ,
47+ ) ;
4348
4449 it ( "preserves comment markers and commas before brackets inside string values" , ( ) => {
4550 expect ( decodeLenientJson ( '"1/* https://example.com */2"' ) ) . toBe ( "1/* https://example.com */2" ) ;
4651 expect ( decodeLenientJson ( '{"note":"a,]"}' ) ) . toEqual ( { note : "a,]" } ) ;
4752 expect ( decodeLenientJson ( '{"list":["x,}"]}' ) ) . toEqual ( { list : [ "x,}" ] } ) ;
4853 expect ( decodeLenientJson ( '{"values":[1, 2,],}' ) ) . toEqual ( { values : [ 1 , 2 ] } ) ;
4954 } ) ;
55+
56+ it ( "keeps properties after CR-terminated comments in mixed line endings" , ( ) => {
57+ expect ( decodeLenientJson ( '{\n"enabled":true,// comment\r"values":[1,2],\n}' ) ) . toEqual ( {
58+ enabled : true ,
59+ values : [ 1 , 2 ] ,
60+ } ) ;
61+ } ) ;
5062} ) ;
0 commit comments