diff options
| -rw-r--r-- | tests/modules/os/test.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 2 |
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", ".*") |
