diff --git a/jsonexamples/invalid/nil_token.json b/jsonexamples/invalid/nil_token.json new file mode 100644 index 0000000..afaf04b --- /dev/null +++ b/jsonexamples/invalid/nil_token.json @@ -0,0 +1 @@ +[nil] diff --git a/jsonexamples/invalid/nil_token_scalar.json b/jsonexamples/invalid/nil_token_scalar.json new file mode 100644 index 0000000..607602c --- /dev/null +++ b/jsonexamples/invalid/nil_token_scalar.json @@ -0,0 +1 @@ +nil diff --git a/jsonexamples/invalid/nully_token.json b/jsonexamples/invalid/nully_token.json new file mode 100644 index 0000000..f7e40fb --- /dev/null +++ b/jsonexamples/invalid/nully_token.json @@ -0,0 +1 @@ +[nully] diff --git a/jsonexamples/invalid/nully_token_scalar.json b/jsonexamples/invalid/nully_token_scalar.json new file mode 100644 index 0000000..1307f40 --- /dev/null +++ b/jsonexamples/invalid/nully_token_scalar.json @@ -0,0 +1 @@ +nully diff --git a/spec/compile_spec.lua b/spec/compile_spec.lua index 49053e5..22e191b 100644 --- a/spec/compile_spec.lua +++ b/spec/compile_spec.lua @@ -107,7 +107,11 @@ if tonumber(major) >= 5 and tonumber(minor) >= 3 then end local invalid_files = { - "bool_trailing.json" + "bool_trailing.json", + "nil_token.json", + -- "nil_token_scalar.json", + "nully_token.json", + -- "nully_token_scalar.json" } describe("Make sure invalid files are not accepted", function() 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; } }