Skip to content

Commit 2714aa0

Browse files
committed
Fix TOML parse failure when number token hits buffer edge
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
1 parent d7772d5 commit 2714aa0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,4 +1016,12 @@ 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+
public void longInput() throws IOException {
1022+
toml(
1023+
"foo = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" +
1024+
"bar = 678\n" +
1025+
"baz = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"");
1026+
}
10191027
}

0 commit comments

Comments
 (0)