Don't choke on failed node name parsing

This commit is contained in:
Brandon Dyck 2024-08-02 16:49:31 -06:00
parent 71d2e537dd
commit 4a810e9964
2 changed files with 13 additions and 1 deletions

View File

@ -11,7 +11,11 @@ end
local function setup(db)
db:create_function("parse_node_name", 1, function(ctx, table_name)
local obj = csexp.parse(table_name)
local ok, obj = pcall(csexp.parse, table_name)
if not ok then
ctx:result_null()
return
end
if type(obj) ~= "table" or obj[1] ~= "node" then
ctx:result_null()
return

View File

@ -44,4 +44,12 @@ describe("schema", function()
expect.equal(expected, actual)
end)
end)
describe("parse_node_name", function()
it("returns NULL on non-sexp table names", function()
for val in db:urows("SELECT parse_node_name('not a sexp')") do
expect.not_exist(val)
end
end)
end)
end)