Skip to content

Commit 51caa03

Browse files
yawkattimyates
andauthored
Fix TOML parse failure when number token hits buffer edge (#95)
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]>
1 parent bf07dfa commit 51caa03

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

toml/src/main/java/io/micronaut/toml/Parser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ private JsonNode parseInt(int nextState) throws IOException {
256256
}
257257
}
258258

259+
JsonNode v = parseInt0(buffer, start, length);
259260
pollExpected(TomlToken.INTEGER, nextState);
261+
return v;
262+
}
263+
264+
private JsonNode parseInt0(char[] buffer, int start, int length) throws TomlStreamReadException {
260265
if (length > 2) {
261266
char baseChar = buffer[start + 1];
262267
if (baseChar == 'x' || baseChar == 'o' || baseChar == 'b') {

toml/src/test/java/io/micronaut/toml/ParserTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,4 +1016,14 @@ public void unknownEscape() throws IOException {
10161016
Assertions.assertThrows(TomlStreamReadException.class, () -> toml("foo = \"\\k\"")).getOriginalMessage(),
10171017
Matchers.containsString("Unknown escape sequence"));
10181018
}
1019+
1020+
@Test
1021+
// https://github.com/micronaut-projects/micronaut-toml/pull/95
1022+
void longInput() {
1023+
Assertions.assertDoesNotThrow(() -> toml(
1024+
"foo = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" +
1025+
"bar = 678\n" +
1026+
"baz = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
1027+
));
1028+
}
10191029
}

0 commit comments

Comments
 (0)