Skip to content

Commit 4a65dc5

Browse files
authored
Reject invalid non-null tokens beginning with n (#93)
* Add test cases for invalid n tokens Tokens that begin with `n` should not be treated as `null`. * Reject non-null tokens beginning with n In 0f609dd, a regression was introduced where the parser would read any token that started with n as null. The `.type()` method returns `json_type::null` simply if the token begins with `n`, and it does not check whether the token is actually valid. Adding an `is_null()` call here ensures this and returns an error if the token starts with `n` but is not `null`. Calling `.value()` on the returned value will raise it as an exception if `is_null()` returned an error. Currently with simdjson 3.10.1, there is a bug where calling `is_null` on a document object lacks this behaviour, so currently this patch only fixes the problem for non-scalar documents. * Comment out broken tests for now
1 parent 8e18887 commit 4a65dc5

6 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[nil]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nil
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[nully]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nully

spec/compile_spec.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ if tonumber(major) >= 5 and tonumber(minor) >= 3 then
107107
end
108108

109109
local invalid_files = {
110-
"bool_trailing.json"
110+
"bool_trailing.json",
111+
"nil_token.json",
112+
-- "nil_token_scalar.json",
113+
"nully_token.json",
114+
-- "nully_token_scalar.json"
111115
}
112116

113117
describe("Make sure invalid files are not accepted", function()

src/luasimdjson.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ void convert_ondemand_element_to_table(lua_State *L, T& element) {
121121
break;
122122

123123
case ondemand::json_type::null:
124-
lua_pushlightuserdata(L, NULL);
124+
// calling is_null().value() will trigger an exception if the value is invalid
125+
if (element.is_null().value()) {
126+
lua_pushlightuserdata(L, NULL);
127+
}
125128
break;
126129
}
127130
}

0 commit comments

Comments
 (0)