Skip to content

Commit 1434f7a

Browse files
committed
JS: Tolerate trailing comma in JSON array
Previously we'd fail to extract some tsconfig.json files because of this.
1 parent 800dd16 commit 1434f7a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

javascript/extractor/src/com/semmle/js/parser/JSONParser.java

Lines changed: 0 additions & 3 deletions
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 ',':

javascript/extractor/tests/json/output/trap/array-trailing-comma.json.trap

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@ containerparent(#10001,#10000)
77
locations_default(#10002,#10000,0,0,0,0)
88
hasLocation(#10000,#10002)
99
#20000=*
10-
json_errors(#20000,"Error: Omitted elements are not allowed in JSON.")
11-
#20001=@"loc,{#10000},5,4,5,4"
12-
locations_default(#20001,#10000,5,4,5,4)
13-
hasLocation(#20000,#20001)
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)
1432
numlines(#10000,6,0,0)
1533
filetype(#10000,"json")

0 commit comments

Comments
 (0)