diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-20 13:43:44 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-23 20:47:09 -0300 |
commit | 2c4ff5240bf298fec07749f5984de2f08b8736ec (patch) | |
tree | f0b4dfec401fa1a132fc5786467fb8683d17bdcb /spec/dir_spec.lua | |
parent | 79bd1739d8ca004ddd0b2fa5e24da4a6f4b776fa (diff) | |
download | luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.gz luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.bz2 luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.zip |
fix: better normalization for paths and slashes
Fixes #1195.
Diffstat (limited to 'spec/dir_spec.lua')
-rw-r--r-- | spec/dir_spec.lua | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/spec/dir_spec.lua b/spec/dir_spec.lua index f6ef172e..b5dadda8 100644 --- a/spec/dir_spec.lua +++ b/spec/dir_spec.lua | |||
@@ -1,5 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local testing_paths = test_env.testing_paths | 2 | local testing_paths = test_env.testing_paths |
3 | local P = test_env.P | ||
3 | 4 | ||
4 | test_env.unload_luarocks() | 5 | test_env.unload_luarocks() |
5 | test_env.setup_specs() | 6 | test_env.setup_specs() |
@@ -45,26 +46,26 @@ describe("luarocks.dir #unit", function() | |||
45 | 46 | ||
46 | describe("dir.normalize", function() | 47 | describe("dir.normalize", function() |
47 | it("converts backslashes and removes trailing slashes", function() | 48 | it("converts backslashes and removes trailing slashes", function() |
48 | assert.are.same("/foo/ovo", dir.normalize("\\foo\\ovo\\")) | 49 | assert.are.same(P"/foo/ovo", dir.normalize("\\foo\\ovo\\")) |
49 | assert.are.same("c:/some/dir", dir.normalize("c:\\..\\some\\foo\\..\\dir")) | 50 | assert.are.same(P"c:/some/dir", dir.normalize("c:\\..\\some\\foo\\..\\dir")) |
50 | assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\")) | 51 | assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\")) |
51 | end) | 52 | end) |
52 | it("strips unneeded /../ and /./", function() | 53 | it("strips unneeded /../ and /./", function() |
53 | assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) | 54 | assert.are.same(P"/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(P"/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(P"/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./some/subdir/../..")) |
56 | assert.are.same("/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./.")) | 57 | assert.are.same(P"/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./.")) |
57 | end) | 58 | end) |
58 | it("respects relative paths", function() | 59 | it("respects relative paths", function() |
59 | assert.are.same(".", dir.normalize(".")) | 60 | assert.are.same(P".", dir.normalize(".")) |
60 | assert.are.same("boo", dir.normalize("./boo")) | 61 | assert.are.same(P"boo", dir.normalize("./boo")) |
61 | assert.are.same("/boo", dir.normalize("/./boo")) | 62 | assert.are.same(P"/boo", dir.normalize("/./boo")) |
62 | assert.are.same("../../../../boo", dir.normalize("../../../hello/world/../../../boo")) | 63 | assert.are.same(P"../../../../boo", dir.normalize("../../../hello/world/../../../boo")) |
63 | end) | 64 | end) |
64 | it("respects root directory", function() | 65 | it("respects root directory", function() |
65 | assert.are.same("/", dir.normalize("/")) | 66 | assert.are.same(P"/", dir.normalize("/")) |
66 | assert.are.same("/", dir.normalize("/////")) | 67 | assert.are.same(P"/", dir.normalize("/////")) |
67 | assert.are.same("/", dir.normalize("/a/b/.././../c/./../../")) | 68 | assert.are.same(P"/", dir.normalize("/a/b/.././../c/./../../")) |
68 | end) | 69 | end) |
69 | end) | 70 | end) |
70 | 71 | ||