Skip to content

Commit d2a4f1e

Browse files
authored
Merge pull request #19267 from asgerf/js/json-array-trailing-comma
JS: Tolerate trailing commas in JSON arrays
2 parents 0e31bf1 + 3da1f26 commit d2a4f1e

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

Diff for: javascript/extractor/src/com/semmle/js/extractor/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Main {
4242
* A version identifier that should be updated every time the extractor changes in such a way that
4343
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4444
*/
45-
public static final String EXTRACTOR_VERSION = "2025-03-20";
45+
public static final String EXTRACTOR_VERSION = "2025-04-10";
4646

4747
public static final Pattern NEWLINE = Pattern.compile("\n");
4848

Diff for: javascript/extractor/src/com/semmle/js/parser/JSONParser.java

-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ private JSONArray readArray(int startoff, Position start) throws ParseError {
205205
char c = peek();
206206
switch (c) {
207207
case ']':
208-
if (!needsComma) {
209-
raise("Omitted elements are not allowed in JSON.");
210-
}
211208
next();
212209
break out;
213210
case ',':
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"array": [
3+
"foo",
4+
"bar",
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#10000=@"/array-trailing-comma.json;sourcefile"
2+
files(#10000,"/array-trailing-comma.json")
3+
#10001=@"/;folder"
4+
folders(#10001,"/")
5+
containerparent(#10001,#10000)
6+
#10002=@"loc,{#10000},0,0,0,0"
7+
locations_default(#10002,#10000,0,0,0,0)
8+
hasLocation(#10000,#10002)
9+
#20000=*
10+
json(#20000,5,#10000,0,"{\n "" ... ]\n}")
11+
#20001=@"loc,{#10000},1,1,6,1"
12+
locations_default(#20001,#10000,1,1,6,1)
13+
json_locations(#20000,#20001)
14+
#20002=*
15+
json(#20002,4,#20000,0,"[\n ... ,\n ]")
16+
#20003=@"loc,{#10000},2,14,5,5"
17+
locations_default(#20003,#10000,2,14,5,5)
18+
json_locations(#20002,#20003)
19+
#20004=*
20+
json(#20004,3,#20002,0,"""foo""")
21+
#20005=@"loc,{#10000},3,9,3,13"
22+
locations_default(#20005,#10000,3,9,3,13)
23+
json_locations(#20004,#20005)
24+
json_literals("foo","""foo""",#20004)
25+
#20006=*
26+
json(#20006,3,#20002,1,"""bar""")
27+
#20007=@"loc,{#10000},4,9,4,13"
28+
locations_default(#20007,#10000,4,9,4,13)
29+
json_locations(#20006,#20007)
30+
json_literals("bar","""bar""",#20006)
31+
json_properties(#20000,"array",#20002)
32+
numlines(#10000,6,0,0)
33+
filetype(#10000,"json")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a bug that would prevent extraction of `tsconfig.json` files when it contained an array literal with a trailing comma.

0 commit comments

Comments
 (0)