mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 08:46:45 +00:00
Simplify url.parse_query
This commit is contained in:
parent
11561c5686
commit
9371dd1c6b
1 changed files with 4 additions and 21 deletions
|
|
@ -388,33 +388,16 @@ local entities = {
|
|||
-- <code>table["name"]</code> = <code>value</code>.
|
||||
-----------------------------------------------------------------------------
|
||||
function parse_query(query)
|
||||
local parsed = {}
|
||||
local pos = 1
|
||||
|
||||
-- TODO: https://github.com/nmap/nmap/issues/3324
|
||||
-- This opportunistic HTML decoding is problematic because
|
||||
-- it might accidentally decode what should not be decoded.
|
||||
query = string.gsub(query, "&([ampltg]+);", entities)
|
||||
query = string.gsub(query, "%+", " ")
|
||||
|
||||
local function ginsert(qstr)
|
||||
local pos = qstr:find("=", 1, true)
|
||||
if pos then
|
||||
parsed[unescape(qstr:sub(1, pos - 1))] = unescape(qstr:sub(pos + 1))
|
||||
else
|
||||
parsed[unescape(qstr)] = ""
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local first, last = string.find(query, "&", pos, true)
|
||||
if first then
|
||||
ginsert(string.sub(query, pos, first-1));
|
||||
pos = last+1
|
||||
else
|
||||
ginsert(string.sub(query, pos));
|
||||
break;
|
||||
end
|
||||
local parsed = {}
|
||||
for qseg in query:gsub(query, "%+", " "):gmatch("[^&]+") do
|
||||
local k, v = qseg:match("^([^=]*)=?(.*)")
|
||||
parsed[unescape(k)] = unescape(v)
|
||||
end
|
||||
return parsed
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue