From f00ee09f0b0edb89713f2636999b1ad97f225724 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 21 Sep 2024 16:50:29 +0100 Subject: [PATCH] Reject non-null tokens beginning with n In 0f609dd314366858679a168933b03692699e8c6e, 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. --- src/luasimdjson.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/luasimdjson.cpp b/src/luasimdjson.cpp index b657652..fe7ddf9 100644 --- a/src/luasimdjson.cpp +++ b/src/luasimdjson.cpp @@ -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; } }