diff options
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 | ||