mirror of
https://github.com/nmap/nmap.git
synced 2026-08-27 11:55:27 +00:00
Merge 3d6cdfc49a into db4aefddfa
This commit is contained in:
commit
e5d2d68619
1 changed files with 43 additions and 3 deletions
|
|
@ -313,9 +313,19 @@ end
|
|||
-----------------------------------------------------------------------------
|
||||
function parse_path(path)
|
||||
local parsed = {}
|
||||
path = path or ""
|
||||
--path = string.gsub(path, "%s", "")
|
||||
string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)
|
||||
if path == nil or path == "" then
|
||||
return parsed
|
||||
end
|
||||
for slashes, segment in string.gmatch(path, "(/*)([^/]*)") do
|
||||
-- Append empty segments to ensure presence of consecutive `/` isn't lost.
|
||||
for _ = 1, string.len(slashes) - 1 do
|
||||
table.insert(parsed, "")
|
||||
end
|
||||
-- Append path segment
|
||||
if segment ~= "" then
|
||||
table.insert(parsed, segment)
|
||||
end
|
||||
end
|
||||
for i, v in ipairs(parsed) do
|
||||
parsed[i] = unescape(v)
|
||||
end
|
||||
|
|
@ -513,6 +523,36 @@ for _, t in ipairs(test_urls) do
|
|||
end
|
||||
|
||||
|
||||
local parse_path_tests = {
|
||||
-- path, expected_tbl, expected_tbl_size
|
||||
{"/", {}, 0},
|
||||
{"//", {""}, 1},
|
||||
{"///", {"", ""}, 2},
|
||||
{"/test", {"test"}, 1},
|
||||
{"/test/", {"test"}, 1},
|
||||
{"/test//", {"test", ""}, 2},
|
||||
{"/test//test", {"test", "", "test"}, 3},
|
||||
{"/test//test/", {"test", "", "test"}, 3},
|
||||
}
|
||||
|
||||
for test_k, test_v in ipairs(parse_path_tests) do
|
||||
local path, expected_tbl, expected_tbl_size = table.unpack(test_v)
|
||||
local parsed_path = parse_path(path)
|
||||
|
||||
local parsed_path_size = 0
|
||||
for expected_k, expected_v in pairs(expected_tbl) do
|
||||
test_suite:add_test(
|
||||
unittest.equal(parsed_path[expected_k], expected_v),
|
||||
("parse_path #%d `%q` - tbl key `%q`"):format(test_k, path, expected_k)
|
||||
)
|
||||
parsed_path_size = parsed_path_size + 1
|
||||
end
|
||||
test_suite:add_test(
|
||||
unittest.equal(parsed_path_size, expected_tbl_size),
|
||||
("parse_path #%d `%q` - tbl size"):format(test_k, path)
|
||||
)
|
||||
end
|
||||
|
||||
-- path merging tests for compliance with RFC 3986, section 5.2
|
||||
-- https://tools.ietf.org/html/rfc3986#section-5.2
|
||||
local absolute_path_tests = { -- {bpath, rpath, expected}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue