aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Westbrook <github@westbrook.io>2018-08-21 09:59:45 -0600
committerE. Westbrook <github@westbrook.io>2018-08-21 09:59:45 -0600
commit7ccea58776b8084f29a48610cb44b17ca604e4b5 (patch)
tree72dfafe326432f522be33b54170e92d7c4c9a382
parentc570a32c219c957fd405ed018f2500f06952c043 (diff)
downloadluasocket-7ccea58776b8084f29a48610cb44b17ca604e4b5.tar.gz
luasocket-7ccea58776b8084f29a48610cb44b17ca604e4b5.tar.bz2
luasocket-7ccea58776b8084f29a48610cb44b17ca604e4b5.zip
url.lua:remove_dot_components(): avoid overconsuming dot segments
-rw-r--r--src/url.lua4
-rw-r--r--test/urltest.lua5
2 files changed, 7 insertions, 2 deletions
diff --git a/src/url.lua b/src/url.lua
index 0d88adb..e1fa2bc 100644
--- a/src/url.lua
+++ b/src/url.lua
@@ -85,11 +85,11 @@ end
85local function remove_dot_components(path) 85local function remove_dot_components(path)
86 repeat 86 repeat
87 local was = path 87 local was = path
88 path = path:gsub('/%./', '/') 88 path = path:gsub('/%./', '/', 1)
89 until path == was 89 until path == was
90 repeat 90 repeat
91 local was = path 91 local was = path
92 path = path:gsub('[^/]+/%.%./([^/]+)', '%1') 92 path = path:gsub('[^/]+/%.%./([^/]+)', '%1', 1)
93 until path == was 93 until path == was
94 path = path:gsub('[^/]+/%.%./*$', '') 94 path = path:gsub('[^/]+/%.%./*$', '')
95 path = path:gsub('/%.%.$', '/') 95 path = path:gsub('/%.%.$', '/')
diff --git a/test/urltest.lua b/test/urltest.lua
index 8664fa6..04b3c7f 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -654,6 +654,7 @@ check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g")
654check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") 654check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/")
655check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") 655check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/")
656check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") 656check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g")
657check_absolute_url("http://a/b/c/d;p?q#f", "../../../g", "http://a/g")
657check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") 658check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f")
658check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g") 659check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g")
659check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/g") 660check_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",
686 "http://velox.telemar.com.br/dashboard/index.html") 687 "http://velox.telemar.com.br/dashboard/index.html")
687check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/") 688check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/")
688check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/") 689check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/")
690check_absolute_url("http://example.com/a/b/c/d/", "../q", "http://example.com/a/b/c/q")
691check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com/a/b/q")
692check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q")
693check_absolute_url("http://example.com/a/b/c/d/", "../../../../q", "http://example.com/q")
689 694
690print("testing path parsing and composition") 695print("testing path parsing and composition")
691check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) 696check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })