From f5b4aab9ea59efccf67d6d76c18bf36e65af41a8 Mon Sep 17 00:00:00 2001 From: Vadim1987 Date: Thu, 2 Jul 2026 13:25:37 +0200 Subject: [PATCH] fix: correct malformed type() checks (C7) --- src/model/input/userInputModel.lua | 2 +- src/model/lang/md/parser.lua | 2 +- src/util/table.lua | 6 +++--- tests/input/user_input_model_spec.lua | 10 ++++++++++ tests/util/table_spec.lua | 8 ++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/model/input/userInputModel.lua b/src/model/input/userInputModel.lua index 4613feec..e4d916f9 100644 --- a/src/model/input/userInputModel.lua +++ b/src/model/input/userInputModel.lua @@ -867,7 +867,7 @@ end function UserInputModel:set_error(errors) self.error = nil if type(errors) == "table" then - if type(errors[1] == "string") then + if type(errors[1]) == "string" then self.error = errors else self.error = {} diff --git a/src/model/lang/md/parser.lua b/src/model/lang/md/parser.lua index d5fccf89..1b0143f2 100644 --- a/src/model/lang/md/parser.lua +++ b/src/model/lang/md/parser.lua @@ -78,7 +78,7 @@ local function parse(input, skip_posinfo) end local function is_lua_block(t) - if not type(t) == "table" then return false end + if type(t) ~= "table" then return false end return t.t == 'code_block' and t.lang == 'lua' end diff --git a/src/util/table.lua b/src/util/table.lua index 81772d6d..70ddc8ab 100644 --- a/src/util/table.lua +++ b/src/util/table.lua @@ -198,7 +198,7 @@ end --- @param self table --- @return boolean is_array function table.is_array(self) - if not self or not type(self) == "table" then + if not self or type(self) ~= "table" then return false end local is_array = true @@ -215,7 +215,7 @@ end --- @param depth integer? --- @return table? function table.flatten(self, depth) - if not self or not type(self) == "table" then + if not self or type(self) ~= "table" then return end local d = depth or 1 @@ -236,7 +236,7 @@ end --- @param self table --- @return table? function table.odds(self) - if not self or not type(self) == "table" then + if not self or type(self) ~= "table" then return end local ret = {} diff --git a/tests/input/user_input_model_spec.lua b/tests/input/user_input_model_spec.lua index f001b02f..56413458 100644 --- a/tests/input/user_input_model_spec.lua +++ b/tests/input/user_input_model_spec.lua @@ -30,6 +30,16 @@ describe("input model spec #input", function() ----------------- -- ASCII -- ----------------- + describe('errors', function() + it('converts non-string errors', function() + local model = UserInputModel(mockConf, luaEval) + --- @diagnostic disable-next-line: invisible + model:set_error({ 42 }) + --- @diagnostic disable-next-line: invisible + assert.same({ '42' }, model.error) + end) + end) + describe('basics', function() local model = UserInputModel(mockConf, luaEval) diff --git a/tests/util/table_spec.lua b/tests/util/table_spec.lua index 95607650..200cbc0e 100644 --- a/tests/util/table_spec.lua +++ b/tests/util/table_spec.lua @@ -13,6 +13,10 @@ describe('table utils #table', function() assert.is_false(table.is_array(t3)) assert.is_false(table.is_array(t4)) end) + it('rejects non-tables', function() + assert.is_false(table.is_array('str')) + assert.is_false(table.is_array(42)) + end) end) describe('odds', function() @@ -26,6 +30,10 @@ describe('table utils #table', function() end) describe('flatten', function() + it('rejects non-tables', function() + assert.is_nil(table.flatten(42)) + end) + it('one deep', function() assert.same({}, table.flatten({}))