summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md8
-rw-r--r--tests/modules/path/test.lua10
-rw-r--r--xmake/core/base/path.lua8
3 files changed, 23 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 094ae16b8..95e10a350 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## master (unreleased)
+### Bugs fixed
+
+* [#2005](https://github.com/xmake-io/xmake/issues/2005): Fix path.extension
+
## v2.6.3
### New features
@@ -1191,6 +1195,10 @@
## master (开发中)
+### Bugs 修复
+
+* [#2005](https://github.com/xmake-io/xmake/issues/2005): Fix path.extension
+
## v2.6.3
### 新特性
diff --git a/tests/modules/path/test.lua b/tests/modules/path/test.lua
index 4217dec16..80e87c5aa 100644
--- a/tests/modules/path/test.lua
+++ b/tests/modules/path/test.lua
@@ -24,4 +24,12 @@ function test_splitenv_unix(t)
t:are_equal(path.splitenv('a%tag:b%tag'), {'a','b'})
t:are_equal(path.splitenv('a%tag:b%%tag%%'), {'a','b'})
t:are_equal(path.splitenv('a%tag:b:%tag:'), {'a','b'})
-end \ No newline at end of file
+end
+
+function test_extension(t)
+ t:are_equal(path.extension("1.1/abc"), "")
+ t:are_equal(path.extension("1.1\\abc"), "")
+ t:are_equal(path.extension("foo.so"), ".so")
+ t:are_equal(path.extension("/home/foo.so"), ".so")
+ t:are_equal(path.extension("\\home\\foo.so"), ".so")
+end
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index 18dbc6b01..92b926705 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -72,10 +72,14 @@ end
function path.extension(p, level)
local i = p:lastof(".", true)
if i then
+ local ext = p:sub(i)
+ if ext:find("[/\\]") then
+ return ""
+ end
if level and level > 1 then
- return path.extension(p:sub(1, i - 1), level - 1) .. p:sub(i)
+ return path.extension(p:sub(1, i - 1), level - 1) .. ext
end
- return p:sub(i)
+ return ext
else
return ""
end