Merge pull request #982 from MihailRis/fix-file-ext

fix file.ext
This commit is contained in:
MihailRis 2026-09-20 22:40:20 +03:00 • committed by GitHub
commit 5ecbeeda7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -1,3 +1,9 @@
debug.log("file extension")
asserts.equals(nil, file.ext("config:test"))
asserts.equals("cfg", file.ext("config:test.cfg"))
asserts.equals("gz", file.ext("config:test.cfg.gz"))
asserts.equals("config:test.cfg", file.remove_ext("config:test.cfg.gz"))
debug.log("check initial state")
assert(file.exists("config:"))

View file

@ -8,7 +8,7 @@ function file.stem(path)
end
function file.ext(path)
return path:match("%.([^:/\\]+)$")
return path:match("[^:/\\.]%.([^.:/\\]+)$")
end
function file.prefix(path)
@ -24,7 +24,11 @@ function file.parent(path)
end
function file.remove_ext(path)
return string.format("%s/%s", file.parent(path), file.stem(path))
local ext = file.ext(path)
if not ext then
return path
end
return path:sub(1, -#ext - 2)
end
function file.path(path)