diff options
author | E. Westbrook <github@westbrook.io> | 2018-08-19 11:32:42 -0600 |
---|---|---|
committer | E. Westbrook <github@westbrook.io> | 2018-08-19 11:32:42 -0600 |
commit | 17a95c126a178b17292637785c6ec09bb1180493 (patch) | |
tree | d5c6115c0330df2c4d7f845bdd52e2d348828ffc /src | |
parent | 5813cd05054599b0409480d3214f1827c2360467 (diff) | |
download | luasocket-17a95c126a178b17292637785c6ec09bb1180493.tar.gz luasocket-17a95c126a178b17292637785c6ec09bb1180493.tar.bz2 luasocket-17a95c126a178b17292637785c6ec09bb1180493.zip |
url.lua:absolute_path(): fix issue #254, simplify, add more test cases
Diffstat (limited to 'src')
-rw-r--r-- | src/url.lua | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/url.lua b/src/url.lua index 110ea94..29b6734 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -88,20 +88,18 @@ local function absolute_path(base_path, relative_path) | |||
88 | if string.sub(relative_path, 1, 1) == "/" then return relative_path end | 88 | if string.sub(relative_path, 1, 1) == "/" then return relative_path end |
89 | local path = string.gsub(base_path, "[^/]*$", "") | 89 | local path = string.gsub(base_path, "[^/]*$", "") |
90 | path = path .. relative_path | 90 | path = path .. relative_path |
91 | path = string.gsub(path, "([^/]*%./)", function (s) | 91 | repeat |
92 | if s ~= "./" then return s else return "" end | 92 | local was = path |
93 | end) | 93 | path = path:gsub('/%./', '/') |
94 | path = string.gsub(path, "/%.$", "/") | 94 | until path == was |
95 | local reduced | 95 | repeat |
96 | while reduced ~= path do | 96 | local was = path |
97 | reduced = path | 97 | path = path:gsub('[^/]+/%.%./([^/]+)', '%1') |
98 | path = string.gsub(reduced, "([^/]*/%.%./)", function (s) | 98 | until path == was |
99 | if s ~= "../../" then return "" else return s end | 99 | path = path:gsub('[^/]+/%.%./*$', '') |
100 | end) | 100 | path = path:gsub('/%.%.$', '/') |
101 | end | 101 | path = path:gsub('/%.$', '/') |
102 | path = string.gsub(reduced, "([^/]*/%.%.)$", function (s) | 102 | path = path:gsub('^/%.%.', '') |
103 | if s ~= "../.." then return "" else return s end | ||
104 | end) | ||
105 | return path | 103 | return path |
106 | end | 104 | end |
107 | 105 | ||