Skip to content

Commit 5a4fe1b

Browse files
committed
JS: Stop complaining about comments in JSON files
1 parent 3c1456b commit 5a4fe1b

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.semmle.util.io.WholeIO;
2222
import java.io.File;
2323
import java.util.ArrayList;
24+
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.regex.Matcher;
2627
import java.util.regex.Pattern;
@@ -32,7 +33,6 @@ public class JSONParser {
3233
private int offset;
3334
private int length;
3435
private String src;
35-
private List<ParseError> recoverableErrors;
3636

3737
public static Pair<JSONValue, List<ParseError>> parseValue(String json) throws ParseError {
3838
JSONParser parser = new JSONParser(json);
@@ -41,14 +41,13 @@ public static Pair<JSONValue, List<ParseError>> parseValue(String json) throws P
4141
parser.consumeWhitespace();
4242
if (parser.offset < parser.length) parser.raise("Expected end of input");
4343

44-
return Pair.make(value, parser.recoverableErrors);
44+
return Pair.make(value, Collections.emptyList());
4545
}
4646

4747
private JSONParser(String json) throws ParseError {
4848
this.line = 1;
4949
this.column = 0;
5050
this.offset = 0;
51-
this.recoverableErrors = new ArrayList<ParseError>();
5251

5352
if (json == null) raise("Input string may not be null");
5453
this.length = json.length();
@@ -351,17 +350,16 @@ private void consumeWhitespace() throws ParseError {
351350
}
352351
}
353352

354-
/** Skips the line comment starting at the current position and records a recoverable error. */
353+
/** Skips the line comment starting at the current position. */
355354
private void skipLineComment() throws ParseError {
356355
Position pos = new Position(line, column, offset);
357356
char c;
358357
next();
359358
next();
360359
while ((c = peek()) != '\r' && c != '\n' && c != -1) next();
361-
recoverableErrors.add(new ParseError("Comments are not legal in JSON.", pos));
362360
}
363361

364-
/** Skips the block comment starting at the current position and records a recoverable error. */
362+
/** Skips the block comment starting at the current position. */
365363
private void skipBlockComment() throws ParseError {
366364
Position pos = new Position(line, column, offset);
367365
char c;
@@ -376,7 +374,6 @@ private void skipBlockComment() throws ParseError {
376374
break;
377375
}
378376
} while (true);
379-
recoverableErrors.add(new ParseError("Comments are not legal in JSON.", pos));
380377
}
381378

382379
private void consume(char token) throws ParseError {

javascript/extractor/tests/json/output/trap/comments.json.trap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,5 @@ locations_default(#20003,#10000,3,12,3,18)
1818
json_locations(#20002,#20003)
1919
json_literals("world","""world""",#20002)
2020
json_properties(#20000,"hello",#20002)
21-
#20004=*
22-
json_errors(#20004,"Error: Comments are not legal in JSON.")
23-
#20005=@"loc,{#10000},2,3,2,3"
24-
locations_default(#20005,#10000,2,3,2,3)
25-
json_locations(#20004,#20005)
26-
#20006=*
27-
json_errors(#20006,"Error: Comments are not legal in JSON.")
28-
#20007=@"loc,{#10000},4,3,4,3"
29-
locations_default(#20007,#10000,4,3,4,3)
30-
json_locations(#20006,#20007)
3121
numlines(#10000,5,0,0)
3222
filetype(#10000,"json")

0 commit comments

Comments
 (0)