Skip to content

Commit

Permalink
GROOVY-11123: allow EOF terminated Number tokens in JsonLexer
Browse files Browse the repository at this point in the history
  • Loading branch information
jekkel authored and paulk-asert committed Jul 14, 2023
1 parent 0833d0e commit 47b07c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ public JsonToken nextToken() {
for (;;) {
reader.mark(1);
int read = reader.read();
if (read == -1) return null;
if (read == -1) {
if (currentContent.length() == 0) return null;
read = 32;
}
char lastCharRead = (char) read;

if (lastCharRead >= ZERO && lastCharRead <= NINE ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class JsonLexerTest extends GroovyTestCase {
}

void testNextToken() {
def content = [" true ", " false ", " null ", " -123.456e78 ", " [ ", " ] ", " { ", " } ", " : ", " , "]
def content = [" true ", "true", " false ", "false", " null ", "null", " -123.456e78 ", "-123.456e78", " [ ", " ] ", " { ", " } ", " : ", " , "]

assert content.collect {
def lexer = new JsonLexer(new StringReader(it))
lexer.nextToken().type
lexer.nextToken()?.type
} == [
TRUE, FALSE, NULL, NUMBER,
TRUE, TRUE, FALSE, FALSE, NULL, NULL, NUMBER, NUMBER,
OPEN_BRACKET, CLOSE_BRACKET, OPEN_CURLY, CLOSE_CURLY, COLON, COMMA
]
}
Expand Down Expand Up @@ -120,7 +120,7 @@ class JsonLexerTest extends GroovyTestCase {
}

void testUnescapingWithLexer() {
// use string concatenation so that the unicode escape characters are not decoded
// use string concatenation so that the unicode escape characters are not decoded
// by Groovy's lexer but by the JsonLexer
def lexer = new JsonLexer(new StringReader('"\\' + 'u004A\\' + 'u0053\\' + 'u004F\\' + 'u004E"'))

Expand Down

0 comments on commit 47b07c5

Please sign in to comment.