JS: Stop complaining about comments in JSON files

This commit is contained in:
Asger F
2023-04-27 10:55:36 +02:00
parent 3c1456bd02
commit 5a4fe1b4da
2 changed files with 4 additions and 17 deletions

View File

@@ -21,6 +21,7 @@ import com.semmle.util.exception.Exceptions;
import com.semmle.util.io.WholeIO;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -32,7 +33,6 @@ public class JSONParser {
private int offset;
private int length;
private String src;
private List<ParseError> recoverableErrors;
public static Pair<JSONValue, List<ParseError>> parseValue(String json) throws ParseError {
JSONParser parser = new JSONParser(json);
@@ -41,14 +41,13 @@ public class JSONParser {
parser.consumeWhitespace();
if (parser.offset < parser.length) parser.raise("Expected end of input");
return Pair.make(value, parser.recoverableErrors);
return Pair.make(value, Collections.emptyList());
}
private JSONParser(String json) throws ParseError {
this.line = 1;
this.column = 0;
this.offset = 0;
this.recoverableErrors = new ArrayList<ParseError>();
if (json == null) raise("Input string may not be null");
this.length = json.length();
@@ -351,17 +350,16 @@ public class JSONParser {
}
}
/** Skips the line comment starting at the current position and records a recoverable error. */
/** Skips the line comment starting at the current position. */
private void skipLineComment() throws ParseError {
Position pos = new Position(line, column, offset);
char c;
next();
next();
while ((c = peek()) != '\r' && c != '\n' && c != -1) next();
recoverableErrors.add(new ParseError("Comments are not legal in JSON.", pos));
}
/** Skips the block comment starting at the current position and records a recoverable error. */
/** Skips the block comment starting at the current position. */
private void skipBlockComment() throws ParseError {
Position pos = new Position(line, column, offset);
char c;
@@ -376,7 +374,6 @@ public class JSONParser {
break;
}
} while (true);
recoverableErrors.add(new ParseError("Comments are not legal in JSON.", pos));
}
private void consume(char token) throws ParseError {

View File

@@ -18,15 +18,5 @@ locations_default(#20003,#10000,3,12,3,18)
json_locations(#20002,#20003)
json_literals("world","""world""",#20002)
json_properties(#20000,"hello",#20002)
#20004=*
json_errors(#20004,"Error: Comments are not legal in JSON.")
#20005=@"loc,{#10000},2,3,2,3"
locations_default(#20005,#10000,2,3,2,3)
json_locations(#20004,#20005)
#20006=*
json_errors(#20006,"Error: Comments are not legal in JSON.")
#20007=@"loc,{#10000},4,3,4,3"
locations_default(#20007,#10000,4,3,4,3)
json_locations(#20006,#20007)
numlines(#10000,5,0,0)
filetype(#10000,"json")