mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
url.lua:remove_dot_components(): use temporary NUL marker to reduce empty-segment special-case code
This commit is contained in:
parent
38d936ec0e
commit
ca5398be09
@ -85,11 +85,11 @@ end
|
|||||||
local function remove_dot_components(path)
|
local function remove_dot_components(path)
|
||||||
repeat
|
repeat
|
||||||
local was = path
|
local was = path
|
||||||
path = path:gsub('/%./', '/', 1)
|
path = path:gsub('//', '/'..0x00..'/', 1)
|
||||||
until path == was
|
until path == was
|
||||||
repeat
|
repeat
|
||||||
local was = path
|
local was = path
|
||||||
path = path:gsub('//%.%./([^/]+)', '/%1', 1)
|
path = path:gsub('/%./', '/', 1)
|
||||||
until path == was
|
until path == was
|
||||||
repeat
|
repeat
|
||||||
local was = path
|
local was = path
|
||||||
@ -99,6 +99,7 @@ local function remove_dot_components(path)
|
|||||||
path = path:gsub('/%.%.$', '/')
|
path = path:gsub('/%.%.$', '/')
|
||||||
path = path:gsub('/%.$', '/')
|
path = path:gsub('/%.$', '/')
|
||||||
path = path:gsub('^/%.%./', '/')
|
path = path:gsub('^/%.%./', '/')
|
||||||
|
path = path:gsub(0x00, '')
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -692,6 +692,10 @@ check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com
|
|||||||
check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q")
|
check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q")
|
||||||
check_absolute_url("http://example.com", ".badhost.com", "http://example.com/.badhost.com")
|
check_absolute_url("http://example.com", ".badhost.com", "http://example.com/.badhost.com")
|
||||||
check_absolute_url("http://example.com/a/b/c/d/", "..//../../../q", "http://example.com/a/q")
|
check_absolute_url("http://example.com/a/b/c/d/", "..//../../../q", "http://example.com/a/q")
|
||||||
|
check_absolute_url("http://example.com/a/b/c/d/", "..//a/../../../../q", "http://example.com/a/q")
|
||||||
|
check_absolute_url("http://example.com/a/b/c/d/", "..//a/..//../../../q", "http://example.com/a/b/q")
|
||||||
|
check_absolute_url("http://example.com/a/b/c/d/", "..//a/..///../../../../q", "http://example.com/a/b/q")
|
||||||
|
check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", "http://example.com/a/b/q")
|
||||||
|
|
||||||
print("testing path parsing and composition")
|
print("testing path parsing and composition")
|
||||||
check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })
|
check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })
|
||||||
|
Loading…
Reference in New Issue
Block a user