aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAleksei Volkov <volkov.aa@phystech.edu>2023-10-31 01:39:43 +0300
committerGitHub <noreply@github.com>2023-10-30 19:39:43 -0300
commitb8a2710a2cefbddc5e6b494db186014b341412e4 (patch)
tree137248c695babc7b37fccd42ebda44431a27277d /spec
parentbb9d7ed38a092dde2b27e2adc7b386272f2890ee (diff)
downloadluarocks-b8a2710a2cefbddc5e6b494db186014b341412e4.tar.gz
luarocks-b8a2710a2cefbddc5e6b494db186014b341412e4.tar.bz2
luarocks-b8a2710a2cefbddc5e6b494db186014b341412e4.zip
Fix problems in path normalisation algorithm (#1541)
Current implementation of path normalisation contains various flaws: - Trailing `.` and `..` at the end of path don't get normalised, - Path `/` turns into an empty string after normalisation. This patch changes implementation of normalisation to fix these.
Diffstat (limited to 'spec')
-rw-r--r--spec/dir_spec.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/dir_spec.lua b/spec/dir_spec.lua
index 9f05c664..f6ef172e 100644
--- a/spec/dir_spec.lua
+++ b/spec/dir_spec.lua
@@ -52,12 +52,20 @@ describe("luarocks.dir #unit", function()
52 it("strips unneeded /../ and /./", function() 52 it("strips unneeded /../ and /./", function()
53 assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) 53 assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt"))
54 assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) 54 assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt"))
55 assert.are.same("/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./some/subdir/../.."))
56 assert.are.same("/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./."))
55 end) 57 end)
56 it("respects relative paths", function() 58 it("respects relative paths", function()
59 assert.are.same(".", dir.normalize("."))
57 assert.are.same("boo", dir.normalize("./boo")) 60 assert.are.same("boo", dir.normalize("./boo"))
58 assert.are.same("/boo", dir.normalize("/./boo")) 61 assert.are.same("/boo", dir.normalize("/./boo"))
59 assert.are.same("../../../../boo", dir.normalize("../../../hello/world/../../../boo")) 62 assert.are.same("../../../../boo", dir.normalize("../../../hello/world/../../../boo"))
60 end) 63 end)
64 it("respects root directory", function()
65 assert.are.same("/", dir.normalize("/"))
66 assert.are.same("/", dir.normalize("/////"))
67 assert.are.same("/", dir.normalize("/a/b/.././../c/./../../"))
68 end)
61 end) 69 end)
62 70
63end) 71end)