Skip to content

Commit 152d6f3

Browse files
committed
JS: Tolerate trailing comma in JSON objects
1 parent 6dd8114 commit 152d6f3

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-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
@@ -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) {

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

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

0 commit comments

Comments
 (0)