From 6cbc408102b2278d04ca8aab110c95452e90bbaa Mon Sep 17 00:00:00 2001 From: Selt <83926739+seltonmt012@users.noreply.github.com> Date: Mon, 27 Jul 2026 20:22:11 +0200 Subject: [PATCH 1/2] fix(esx_lib): correct isArray, toPascal and replace helpers Three small logic bugs in the shared helpers, each verified with a standalone Lua run. isArray returned true for sparse tables like {[1]=1,[3]=3}: the in-loop `count > maxIndex` check can never fire (with positive integer keys count is always <= maxIndex), so it was dead code. Dropped it and return `count == maxIndex`, which is false for gaps and still true for a dense sequence or an empty table. toPascal lowercased the letters after an underscore: `[%w_]*` swallowed the underscore and the next word into the part that gets lowercased, so "hello_world" became "Helloworld". Excluding the underscore from that class leaves each word to be capitalised, then the trailing gsub removes the underscores -> "HelloWorld". replace escaped the pattern but not the replacement, so a "%" in the replacement raised "invalid use of '%' in replacement string" and "%1" style sequences expanded captures. Escape "%" in a string replacement; a function or table replacement is left untouched. --- [core]/esx_lib/imports/string/shared.lua | 6 +++++- [core]/esx_lib/imports/table/shared.lua | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/[core]/esx_lib/imports/string/shared.lua b/[core]/esx_lib/imports/string/shared.lua index b6c00867..ba6bc456 100644 --- a/[core]/esx_lib/imports/string/shared.lua +++ b/[core]/esx_lib/imports/string/shared.lua @@ -47,7 +47,7 @@ end function xLib.string.toPascal(s) xLib.verify(s, 'string', true) - local res = s:gsub("(%a)([%w_]*)", function(first, rest) + local res = s:gsub("(%a)([%w]*)", function(first, rest) return first:upper() .. rest:lower() end):gsub("_", "") @@ -114,6 +114,10 @@ end function xLib.string.replace(s, old, new) xLib.verify(s, 'string', true) + if type(new) == "string" then + new = new:gsub("%%", "%%%%") + end + local result = s:gsub(xLib.string.escapePattern(old), new) return result diff --git a/[core]/esx_lib/imports/table/shared.lua b/[core]/esx_lib/imports/table/shared.lua index 1a590f34..37d51ee6 100644 --- a/[core]/esx_lib/imports/table/shared.lua +++ b/[core]/esx_lib/imports/table/shared.lua @@ -14,13 +14,9 @@ function xLib.table.isArray(tbl) end count, maxIndex = count + 1, math.max(maxIndex, k) - - if count > maxIndex then - return false - end end - return true + return count == maxIndex end ---@param tbl table From a890abd11008ccb5ec8055685d6b5d8c1070d1f9 Mon Sep 17 00:00:00 2001 From: Selt <83926739+seltonmt012@users.noreply.github.com> Date: Thu, 30 Jul 2026 01:45:05 +0200 Subject: [PATCH 2/2] fix(esx_lib): make table.dump work and drop the shadowed contains table.dump called its own table argument as a function, so it threw "attempt to call a table value" for every table that had at least one entry. An empty table returned "{ } " and a non-table returned tostring, which is why it looks fine until you actually dump something. table.contains was defined twice in the same file. Lua keeps the second one, so the annotated version further up was unreachable. Removed the unreachable one; behaviour is unchanged. --- [core]/esx_lib/imports/table/shared.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/[core]/esx_lib/imports/table/shared.lua b/[core]/esx_lib/imports/table/shared.lua index 37d51ee6..57940f09 100644 --- a/[core]/esx_lib/imports/table/shared.lua +++ b/[core]/esx_lib/imports/table/shared.lua @@ -34,13 +34,6 @@ function xLib.table.searchForKey(tbl, item) return nil end ----@param tbl table ----@param item any ----@return boolean -function xLib.table.contains(tbl, item) - return xLib.table.searchForKey(tbl, item) ~= nil -end - ---@param tbl table ---@param filter fun(value:any, key:any):boolean ---@return table @@ -118,7 +111,7 @@ function xLib.table.dump(tbl) local s = '{ ' for k,v in pairs(tbl) do if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. tbl(v) .. ',' + s = s .. '['..k..'] = ' .. xLib.table.dump(v) .. ',' end return s .. '} ' else