Skip to content

Commit

Permalink
Reject non-null tokens beginning with n
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tobil4sk committed Sep 24, 2024
1 parent ff86e24 commit f00ee09
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/luasimdjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ void convert_ondemand_element_to_table(lua_State *L, T& element) {
break;

case ondemand::json_type::null:
lua_pushlightuserdata(L, NULL);
// calling is_null().value() will trigger an exception if the value is invalid
if (element.is_null().value()) {
lua_pushlightuserdata(L, NULL);
}
break;
}
}
Expand Down

0 comments on commit f00ee09

Please sign in to comment.