Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add fix for issue #357 - strick parsing of null, true and false keywords
  • Loading branch information
abhisheks-gh committed Jan 1, 2026
commit a658fee5a1f03189af738275abd37ced0edc1b5c
9 changes: 4 additions & 5 deletions src/main/java/com/jsoniter/IterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,12 @@ public static Any readAny(JsonIterator iter) throws IOException {
skipString(iter);
return Any.lazyString(iter.buf, start, iter.head);
case 't':
skipFixedBytes(iter, 3);
return Any.wrap(true);
case 'f':
skipFixedBytes(iter, 4);
return Any.wrap(false);
iter.unreadByte();
return Any.wrap(iter.readBoolean());
case 'n':
skipFixedBytes(iter, 3);
iter.unreadByte();
iter.readNull();
return Any.wrap((Object) null);
case '[':
skipArray(iter);
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/jsoniter/IterImplForStreaming.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,12 @@ public static Any readAny(JsonIterator iter) throws IOException {
byte[] copied = copySkippedBytes(iter);
return Any.lazyString(copied, 0, copied.length);
case 't':
skipFixedBytes(iter, 3);
iter.skipStartedAt = -1;
return Any.wrap(true);
case 'f':
skipFixedBytes(iter, 4);
iter.skipStartedAt = -1;
return Any.wrap(false);
iter.unreadByte();
return Any.wrap(iter.readBoolean());
case 'n':
skipFixedBytes(iter, 3);
iter.skipStartedAt = -1;
iter.unreadByte();
iter.readNull();
return Any.wrap((Object) null);
case '[':
skipArray(iter);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/jsoniter/IterImplObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public static final String readObject(JsonIterator iter) throws IOException {
byte c = IterImpl.nextToken(iter);
switch (c) {
case 'n':
IterImpl.skipFixedBytes(iter, 3);
return null;
iter.unreadByte();
if (iter.readNull()) {
return null;
}
case '{':
c = IterImpl.nextToken(iter);
if (c == '"') {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/jsoniter/IterImplSkip.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public static final void skip(JsonIterator iter) throws IOException {
case '9':
IterImpl.skipUntilBreak(iter);
return;
case 't':
case 'n':
IterImpl.skipFixedBytes(iter, 3); // true or null
iter.unreadByte();
iter.readNull();
return;
case 't':
case 'f':
IterImpl.skipFixedBytes(iter, 4); // false
iter.unreadByte();
iter.readBoolean(); // true or false
return;
case '[':
IterImpl.skipArray(iter);
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/com/jsoniter/JsonIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,34 @@ public final boolean readNull() throws IOException {
unreadByte();
return false;
}
IterImpl.skipFixedBytes(this, 3); // null
return true;
if (IterImpl.readByte(this) == 'u' &&
IterImpl.readByte(this) == 'l' &&
IterImpl.readByte(this) == 'l') {
return true; // null
}
throw reportError("readNull", "expect null");
}

public final boolean readBoolean() throws IOException {
byte c = IterImpl.nextToken(this);
if ('t' == c) {
IterImpl.skipFixedBytes(this, 3); // true
return true;
if (IterImpl.readByte(this) == 'r' &&
IterImpl.readByte(this) == 'u' &&
IterImpl.readByte(this) == 'e') {
return true;
}
throw reportError("readBoolean", "expect true");
}
if ('f' == c) {
IterImpl.skipFixedBytes(this, 4); // false
return false;
if (IterImpl.readByte(this) == 'a' &&
IterImpl.readByte(this) == 'l' &&
IterImpl.readByte(this) == 's' &&
IterImpl.readByte(this) == 'e') {
return false;
}
throw reportError("readBoolean", "expect false");
}
throw reportError("readBoolean", "expect t or f, found: " + c);
throw reportError("readBoolean", "expect true or false");
}

public final short readShort() throws IOException {
Expand Down