summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-09-06 15:27:25 +0800
committerGitHub <[email protected]>2026-09-06 15:27:25 +0800
commit2c1fdfbea285c696350e795af7c4d45a2000acf1 (patch)
tree3f8cb32e2ab693f5a8518046a93cfb053df162c3
parent266ac8a9c87209d6a828c140393af042e74d3e6c (diff)
parent8102c104461c1bb71a13e4531c59e23e371d35be (diff)
Merge pull request #7753 from zjncs/fix-path-pattern-escape-bracketsmaster
escape brackets in path.pattern
-rw-r--r--tests/modules/os/test.lua10
-rw-r--r--xmake/core/base/path.lua2
2 files changed, 11 insertions, 1 deletions
diff --git a/tests/modules/os/test.lua b/tests/modules/os/test.lua
index 2dcab35c6..d24615fd4 100644
--- a/tests/modules/os/test.lua
+++ b/tests/modules/os/test.lua
@@ -208,3 +208,13 @@ function test_isexec(t)
os.tryrm(tempdir)
end
+
+function test_files_with_brackets(t)
+ local tmpdir = os.tmpfile() .. ".dir"
+ io.writefile(path.join(tmpdir, "a[1].lua"), "x")
+ io.writefile(path.join(tmpdir, "a1.lua"), "x")
+ -- a wildcard is required, a plain existing file is matched without converting the pattern
+ local files = os.files(path.join(tmpdir, "a[1]*.lua"))
+ t:are_equal(files, {path.join(tmpdir, "a[1].lua")})
+ os.tryrm(tmpdir)
+end
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index ee154147f..79317decf 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -442,7 +442,7 @@ end
function path.pattern(pattern)
-- translate wildcards, e.g. *, **
- pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1")
+ pattern = pattern:gsub("([%+%.%-%^%$%(%)%%%[%]])", "%%%1")
pattern = pattern:gsub("%*%*", "\001")
pattern = pattern:gsub("%*", "\002")
pattern = pattern:gsub("\001", ".*")