diff --git a/assets/.lua/schema.lua b/assets/.lua/schema.lua index 2f9b2dd..bf46d75 100644 --- a/assets/.lua/schema.lua +++ b/assets/.lua/schema.lua @@ -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 diff --git a/tests/test-schema.lua b/tests/test-schema.lua index eb1ee56..f081d32 100644 --- a/tests/test-schema.lua +++ b/tests/test-schema.lua @@ -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) \ No newline at end of file