mirror of
https://github.com/nmap/nmap.git
synced 2025-12-11 10:19:03 +00:00
Avoid __pairs metamethod in stdnse.keys
This allows stdnse.keys to be used in a __pairs metamethod to, for instance, yield keys in sorted order. Using next() bypasses the __pairs metamethod that would be called when pairs() was used. Otherwise, infinite recursion was possible.
This commit is contained in:
@@ -1416,8 +1416,10 @@ end
|
|||||||
-- @return A table of keys
|
-- @return A table of keys
|
||||||
function keys(t)
|
function keys(t)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for k, _ in pairs(t) do
|
local k, v = next(t)
|
||||||
|
while k do
|
||||||
ret[#ret+1] = k
|
ret[#ret+1] = k
|
||||||
|
k, v = next(t, k)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user