Skip to content

Commit

Permalink
json: Actually apply setting trailingDataAccepted
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed May 13, 2024
1 parent 7285e06 commit f235417
Showing 1 changed file with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,21 @@ public Object parseDocument(Reader reader, Config configModel) {
} else {
throw new ParsingException("Invalid first character for a json document: " + firstChar);
}
checkNoTrailingData(input);
return result;
}

int trailing = input.readAndSkip(SPACES);
if (trailing >= 0) {
input.pushBack((char) trailing);
String msg = String.format(
"Invalid data at the end of the JSON document: %s (use JsonParser.setTrailingDataAccepted(true) if you intend this to work)",
input.read(6).toString());
throw new ParsingException(msg);
private void checkNoTrailingData(CharacterInput input) {
if (!trailingDataAccepted) {
int trailing = input.readAndSkip(SPACES);
if (trailing >= 0) {
input.pushBack((char) trailing);
String msg = String.format(
"Invalid data at the end of the JSON document: %s (use JsonParser.setTrailingDataAccepted(true) if you intend this to work)",
input.read(6).toString());
throw new ParsingException(msg);
}
}
return result;
}

/**
Expand Down Expand Up @@ -173,14 +178,7 @@ public void parse(Reader reader, Config destination, ParsingMode parsingMode) {
parsingMode.prepareParsing(destination);
parseObject(input, destination, parsingMode);
}
int trailing = input.readAndSkip(SPACES);
if (trailing >= 0) {
input.pushBack((char) trailing);
String msg = String.format(
"Invalid data at the end of the JSON document: %s (use JsonParser.setTrailingDataAccepted(true) if you intend this to work)",
input.read(6).toString());
throw new ParsingException(msg);
}
checkNoTrailingData(input);
}

/**
Expand Down Expand Up @@ -236,15 +234,7 @@ public void parseList(Reader reader, List<?> destination, ParsingMode parsingMod
throw new ParsingException("Invalid first character for a json array: " + firstChar);
}
parseArray(input, destination, parsingMode, configModel);

int trailing = input.readAndSkip(SPACES);
if (trailing >= 0) {
input.pushBack((char) trailing);
String msg = String.format(
"Invalid data at the end of the JSON document: %s (use JsonParser.setTrailingDataAccepted(true) if you intend this to work)",
input.read(6).toString());
throw new ParsingException(msg);
}
checkNoTrailingData(input);
}

private <T extends Config> T parseObject(CharacterInput input, T config, ParsingMode parsingMode) {
Expand Down

0 comments on commit f235417

Please sign in to comment.