Skip to content

Commit 543b496

Browse files
lukasjm0mus
authored andcommitted
fix parsing of invalid json with jsonvalue (#130)
Signed-off-by: Lukas Jungmann <[email protected]>
1 parent 01ee02a commit 543b496

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

impl/src/main/java/org/glassfish/json/JsonParserImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public JsonLocation getLastCharLocation() {
330330

331331
@Override
332332
public boolean hasNext() {
333-
if (stack.isEmpty() && (currentEvent == Event.END_ARRAY || currentEvent == Event.END_OBJECT)) {
333+
if (stack.isEmpty() && (currentEvent != null && currentEvent.compareTo(Event.KEY_NAME) > 0)) {
334334
JsonToken token = tokenizer.nextToken();
335335
if (token != JsonToken.EOF) {
336336
throw new JsonParsingException(JsonMessages.PARSER_EXPECTED_EOF(token),

tests/src/test/java/org/glassfish/json/tests/JsonParserTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ public void testExceptionsFromHasNext() {
780780

781781
public void testEOFFromHasNext() {
782782
checkExceptionFromHasNext("{ \"d\" : 1 } 2 3 4");
783+
checkExceptionFromHasNext("[ {\"d\" : 1 }] 2 3 4");
784+
checkExceptionFromHasNext("1 2 3 4");
785+
checkExceptionFromHasNext("null 2 3 4");
783786
}
784787

785788
public void testExceptionsFromNext() {

0 commit comments

Comments
 (0)