aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2022-01-27 08:42:54 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2022-01-27 08:42:54 +0100
commit86f2cefde8f51274573aeb6a7ff0c4e0cf59201a (patch)
tree31396a093a9d524aa5aa001955c06e05c482f9ac
parent10d4f0a53a2f8849ce8fb1076248fcac94f8380d (diff)
downloadlite-xl-86f2cefde8f51274573aeb6a7ff0c4e0cf59201a.tar.gz
lite-xl-86f2cefde8f51274573aeb6a7ff0c4e0cf59201a.zip
Fix again bug with invalid ignore_files patternstesting-2.0.5
The pattern cannot be tested in advance as it seems that Lua inspect the pattern only partially, the part that is actually used. We resort to use pcall to catch any error when using the pattern.
-rw-r--r--data/core/init.lua25
1 files changed, 14 insertions, 11 deletions
diff --git a/data/core/init.lua b/data/core/init.lua
index db1dd08b..2476d171 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -136,20 +136,23 @@ local function compile_ignore_files()
-- config.ignore_files could be a simple string...
if type(ipatterns) ~= "table" then ipatterns = {ipatterns} end
for i, pattern in ipairs(ipatterns) do
- -- we ignore malformed pattern that raise an error
- if pcall(string.match, "a", pattern) then
- table.insert(compiled, {
- use_path = pattern:match("/[^/$]"), -- contains a slash but not at the end
- -- An '/' or '/$' at the end means we want to match a directory.
- match_dir = pattern:match(".+/%$?$"), -- to be used as a boolen value
- pattern = pattern -- get the actual pattern
- })
- end
+ compiled[i] = {
+ use_path = pattern:match("/[^/$]"), -- contains a slash but not at the end
+ -- An '/' or '/$' at the end means we want to match a directory.
+ match_dir = pattern:match(".+/%$?$"), -- to be used as a boolen value
+ pattern = pattern -- get the actual pattern
+ }
end
return compiled
end
+local function safe_match(s, pattern)
+ local ok, match = pcall(string.match, s, pattern)
+ return ok and match
+end
+
+
local function fileinfo_pass_filter(info, ignore_compiled)
if info.size >= config.file_size_limit * 1e6 then return false end
local basename = common.basename(info.filename)
@@ -158,11 +161,11 @@ local function fileinfo_pass_filter(info, ignore_compiled)
for _, compiled in ipairs(ignore_compiled) do
local test = compiled.use_path and fullname or basename
if compiled.match_dir then
- if info.type == "dir" and string.match(test .. "/", compiled.pattern) then
+ if info.type == "dir" and safe_match(test .. "/", compiled.pattern) then
return false
end
else
- if string.match(test, compiled.pattern) then
+ if safe_match(test, compiled.pattern) then
return false
end
end