From 800dd168c2c9e33f8408c8bc9dd99594a13bded5 Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 10 Apr 2025 07:19:26 +0200 Subject: [PATCH 1/4] JS: Add failing TRAP test for trailing comma --- .../tests/json/input/array-trailing-comma.json | 6 ++++++ .../output/trap/array-trailing-comma.json.trap | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 javascript/extractor/tests/json/input/array-trailing-comma.json create mode 100644 javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap diff --git a/javascript/extractor/tests/json/input/array-trailing-comma.json b/javascript/extractor/tests/json/input/array-trailing-comma.json new file mode 100644 index 000000000000..5658e96a3d0a --- /dev/null +++ b/javascript/extractor/tests/json/input/array-trailing-comma.json @@ -0,0 +1,6 @@ +{ + "array": [ + "foo", + "bar", + ] +} diff --git a/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap b/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap new file mode 100644 index 000000000000..042bf630e8f8 --- /dev/null +++ b/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap @@ -0,0 +1,15 @@ +#10000=@"/array-trailing-comma.json;sourcefile" +files(#10000,"/array-trailing-comma.json") +#10001=@"/;folder" +folders(#10001,"/") +containerparent(#10001,#10000) +#10002=@"loc,{#10000},0,0,0,0" +locations_default(#10002,#10000,0,0,0,0) +hasLocation(#10000,#10002) +#20000=* +json_errors(#20000,"Error: Omitted elements are not allowed in JSON.") +#20001=@"loc,{#10000},5,4,5,4" +locations_default(#20001,#10000,5,4,5,4) +hasLocation(#20000,#20001) +numlines(#10000,6,0,0) +filetype(#10000,"json") From 1434f7acd2a7cb696ac80c87e511815ed9f83e00 Mon Sep 17 00:00:00 2001 From: Asger F Date: Wed, 9 Apr 2025 23:14:56 +0200 Subject: [PATCH 2/4] JS: Tolerate trailing comma in JSON array Previously we'd fail to extract some tsconfig.json files because of this. --- .../src/com/semmle/js/parser/JSONParser.java | 3 --- .../trap/array-trailing-comma.json.trap | 26 ++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/parser/JSONParser.java b/javascript/extractor/src/com/semmle/js/parser/JSONParser.java index 26af68b0cd3c..be55eb8397e0 100644 --- a/javascript/extractor/src/com/semmle/js/parser/JSONParser.java +++ b/javascript/extractor/src/com/semmle/js/parser/JSONParser.java @@ -205,9 +205,6 @@ private JSONArray readArray(int startoff, Position start) throws ParseError { char c = peek(); switch (c) { case ']': - if (!needsComma) { - raise("Omitted elements are not allowed in JSON."); - } next(); break out; case ',': diff --git a/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap b/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap index 042bf630e8f8..77d36908a3be 100644 --- a/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap +++ b/javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap @@ -7,9 +7,27 @@ containerparent(#10001,#10000) locations_default(#10002,#10000,0,0,0,0) hasLocation(#10000,#10002) #20000=* -json_errors(#20000,"Error: Omitted elements are not allowed in JSON.") -#20001=@"loc,{#10000},5,4,5,4" -locations_default(#20001,#10000,5,4,5,4) -hasLocation(#20000,#20001) +json(#20000,5,#10000,0,"{\n "" ... ]\n}") +#20001=@"loc,{#10000},1,1,6,1" +locations_default(#20001,#10000,1,1,6,1) +json_locations(#20000,#20001) +#20002=* +json(#20002,4,#20000,0,"[\n ... ,\n ]") +#20003=@"loc,{#10000},2,14,5,5" +locations_default(#20003,#10000,2,14,5,5) +json_locations(#20002,#20003) +#20004=* +json(#20004,3,#20002,0,"""foo""") +#20005=@"loc,{#10000},3,9,3,13" +locations_default(#20005,#10000,3,9,3,13) +json_locations(#20004,#20005) +json_literals("foo","""foo""",#20004) +#20006=* +json(#20006,3,#20002,1,"""bar""") +#20007=@"loc,{#10000},4,9,4,13" +locations_default(#20007,#10000,4,9,4,13) +json_locations(#20006,#20007) +json_literals("bar","""bar""",#20006) +json_properties(#20000,"array",#20002) numlines(#10000,6,0,0) filetype(#10000,"json") From cfa1a9b603ce16b00d0fdb9d92b102a8790f90fe Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 10 Apr 2025 07:14:38 +0200 Subject: [PATCH 3/4] JS: Update extractor version string --- javascript/extractor/src/com/semmle/js/extractor/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index 0b92711b01da..45691d1d7f42 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -42,7 +42,7 @@ public class Main { * A version identifier that should be updated every time the extractor changes in such a way that * it may produce different tuples for the same file under the same {@link ExtractorConfig}. */ - public static final String EXTRACTOR_VERSION = "2025-03-20"; + public static final String EXTRACTOR_VERSION = "2025-04-10"; public static final Pattern NEWLINE = Pattern.compile("\n"); From 3da1f261f7e51b50181f457a6a3902efb2f9c54e Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 10 Apr 2025 07:21:48 +0200 Subject: [PATCH 4/4] JS: Change note --- .../src/change-notes/2025-04-10-json-array-trailing-comma.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 javascript/ql/src/change-notes/2025-04-10-json-array-trailing-comma.md diff --git a/javascript/ql/src/change-notes/2025-04-10-json-array-trailing-comma.md b/javascript/ql/src/change-notes/2025-04-10-json-array-trailing-comma.md new file mode 100644 index 000000000000..7a0acd541e10 --- /dev/null +++ b/javascript/ql/src/change-notes/2025-04-10-json-array-trailing-comma.md @@ -0,0 +1,4 @@ +--- +category: fix +--- +* Fixed a bug that would prevent extraction of `tsconfig.json` files when it contained an array literal with a trailing comma.