aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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 'src')
-rw-r--r--src/luarocks/core/dir.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua
index 0da88997..46dbeafd 100644
--- a/src/luarocks/core/dir.lua
+++ b/src/luarocks/core/dir.lua
@@ -63,6 +63,7 @@ function dir.normalize(name)
63 if pathname:match("^.:") then 63 if pathname:match("^.:") then
64 drive, pathname = pathname:match("^(.:)(.*)$") 64 drive, pathname = pathname:match("^(.:)(.*)$")
65 end 65 end
66 pathname = pathname .. "/"
66 for piece in pathname:gmatch("(.-)/") do 67 for piece in pathname:gmatch("(.-)/") do
67 if piece == ".." then 68 if piece == ".." then
68 local prev = pieces[#pieces] 69 local prev = pieces[#pieces]
@@ -75,11 +76,13 @@ function dir.normalize(name)
75 table.insert(pieces, piece) 76 table.insert(pieces, piece)
76 end 77 end
77 end 78 end
78 local basename = pathname:match("[^/]+$") 79 if #pieces == 0 then
79 if basename then 80 pathname = drive .. "."
80 table.insert(pieces, basename) 81 elseif #pieces == 1 and pieces[1] == "" then
82 pathname = drive .. "/"
83 else
84 pathname = drive .. table.concat(pieces, "/")
81 end 85 end
82 pathname = drive .. table.concat(pieces, "/")
83 if protocol ~= "file" then pathname = protocol .."://"..pathname end 86 if protocol ~= "file" then pathname = protocol .."://"..pathname end
84 return pathname 87 return pathname
85end 88end