Skip to content

Commit 6e64a22

Browse files
authored
Merge pull request #19393 from asgerf/js/json-extractor-trailing-commas2
JS: Tolerate trailing commas in JSON objects
2 parents 966b746 + 152d6f3 commit 6e64a22

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
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
@@ -152,9 +152,6 @@ private JSONObject readObject(int startoff, Position start) throws ParseError {
152152
char c = next();
153153
switch (c) {
154154
case '}':
155-
if (!needsComma) {
156-
raise("Trailing commas are not allowed in JSON.");
157-
}
158155
break out;
159156
case ',':
160157
if (!needsComma) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"object": {
3+
"foo": 1,
4+
"bar": 2,
5+
}
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#10000=@"/object-trailing-comma.json;sourcefile"
2+
files(#10000,"/object-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,5,#20000,0,"{\n ... ,\n }")
16+
#20003=@"loc,{#10000},2,15,5,5"
17+
locations_default(#20003,#10000,2,15,5,5)
18+
json_locations(#20002,#20003)
19+
#20004=*
20+
json(#20004,2,#20002,0,"1")
21+
#20005=@"loc,{#10000},3,16,3,16"
22+
locations_default(#20005,#10000,3,16,3,16)
23+
json_locations(#20004,#20005)
24+
json_literals("1","1",#20004)
25+
json_properties(#20002,"foo",#20004)
26+
#20006=*
27+
json(#20006,2,#20002,1,"2")
28+
#20007=@"loc,{#10000},4,16,4,16"
29+
locations_default(#20007,#10000,4,16,4,16)
30+
json_locations(#20006,#20007)
31+
json_literals("2","2",#20006)
32+
json_properties(#20002,"bar",#20006)
33+
json_properties(#20000,"object",#20002)
34+
numlines(#10000,6,0,0)
35+
filetype(#10000,"json")

0 commit comments

Comments
 (0)