1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-25 17:09:02 +00:00

Forces escape/unescape to return only one value

Otherwise secondary values from string.gsub were leaking over, causing
issues with code constructs like { url.escape(str) }
This commit is contained in:
nnposter
2019-02-10 22:53:58 +00:00
parent 75eed6799c
commit 4b3c5dfcb4

View File

@@ -115,9 +115,10 @@ end
-- @return Escaped representation of string.
-----------------------------------------------------------------------------
function escape(s)
return string.gsub(s, "([^A-Za-z0-9_.~-])", function(c)
local ret = string.gsub(s, "([^A-Za-z0-9_.~-])", function(c)
return string.format("%%%02x", string.byte(c))
end)
return ret
end
@@ -127,9 +128,10 @@ end
-- @return Decoded string.
-----------------------------------------------------------------------------
function unescape(s)
return string.gsub(s, "%%(%x%x)", function(hex)
local ret = string.gsub(s, "%%(%x%x)", function(hex)
return string.char(base.tonumber(hex, 16))
end)
return ret
end