url.lua:remove_dot_components(): avoid overconsuming dot segments

This commit is contained in:
E. Westbrook 2018-08-21 09:59:45 -06:00
parent c570a32c21
commit 7ccea58776
2 changed files with 7 additions and 2 deletions

View File

@ -85,11 +85,11 @@ end
local function remove_dot_components(path)
repeat
local was = path
path = path:gsub('/%./', '/')
path = path:gsub('/%./', '/', 1)
until path == was
repeat
local was = path
path = path:gsub('[^/]+/%.%./([^/]+)', '%1')
path = path:gsub('[^/]+/%.%./([^/]+)', '%1', 1)
until path == was
path = path:gsub('[^/]+/%.%./*$', '')
path = path:gsub('/%.%.$', '/')

View File

@ -654,6 +654,7 @@ check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g")
check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/")
check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/")
check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g")
check_absolute_url("http://a/b/c/d;p?q#f", "../../../g", "http://a/g")
check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f")
check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g")
check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/g")
@ -686,6 +687,10 @@ check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html",
"http://velox.telemar.com.br/dashboard/index.html")
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/b/c/q")
check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com/a/b/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/", "../../../../q", "http://example.com/q")
print("testing path parsing and composition")
check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })