Skip to content

Commit

Permalink
Fix TOML parse failure when number token hits buffer edge (#95)
Browse files Browse the repository at this point in the history
When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue.

Also tracked as FasterXML/jackson-dataformats-text#356

Fixes #93

Co-authored-by: Tim Yates <[email protected]>
  • Loading branch information
yawkat and timyates authored Nov 23, 2022
1 parent bf07dfa commit 51caa03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions toml/src/main/java/io/micronaut/toml/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ private JsonNode parseInt(int nextState) throws IOException {
}
}

JsonNode v = parseInt0(buffer, start, length);
pollExpected(TomlToken.INTEGER, nextState);
return v;
}

private JsonNode parseInt0(char[] buffer, int start, int length) throws TomlStreamReadException {
if (length > 2) {
char baseChar = buffer[start + 1];
if (baseChar == 'x' || baseChar == 'o' || baseChar == 'b') {
Expand Down
10 changes: 10 additions & 0 deletions toml/src/test/java/io/micronaut/toml/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,4 +1016,14 @@ public void unknownEscape() throws IOException {
Assertions.assertThrows(TomlStreamReadException.class, () -> toml("foo = \"\\k\"")).getOriginalMessage(),
Matchers.containsString("Unknown escape sequence"));
}

@Test
// https://github.com/micronaut-projects/micronaut-toml/pull/95
void longInput() {
Assertions.assertDoesNotThrow(() -> toml(
"foo = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" +
"bar = 678\n" +
"baz = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
));
}
}

0 comments on commit 51caa03

Please sign in to comment.