Skip to content

Commit 211e0d2

Browse files
authored
Merge pull request #17 from sagrada1788/master
bugfix: same ipv6 prefix with the same mask
2 parents 1a0a1c5 + 7f3e1ef commit 211e0d2

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

resty/ipmatcher.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ local function new(ips, with_value)
243243
else
244244
node[inet] = true
245245
end
246-
247-
elseif not node[inet] then
248-
node[inet] = {}
249-
node = node[inet]
250246
end
247+
node[inet] = node[inet] or {}
248+
node = node[inet]
251249
end
252250

253251
parsed_ipv6s_mask[ip_addr_mask] = true

t/sanity.t

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,32 @@ GET /t
408408
--- response_body
409409
true
410410
true
411+
412+
413+
414+
=== TEST 13: bug fixing: same ipv6 prefix with the same mask
415+
--- config
416+
location /t {
417+
content_by_lua_block {
418+
local ip = require("resty.ipmatcher").new({
419+
'2409:8928:6a00::/39',
420+
'2409:8928:a000::/39', -- 2409:8928:a000:: - 2409:8928:a1ff:ffff:ffff:ffff:ffff:ffff
421+
})
422+
423+
ngx.say(ip:match("2409:8928:6a00:2a57:1:1:d823:4521"))
424+
ngx.say(ip:match("2409:8928:6a01::"))
425+
ngx.say(ip:match("2409:8928:a0f8:2a57:1:1:d823:4521"))
426+
ngx.say(ip:match("2409:8928:a100::"))
427+
ngx.say(ip:match("2409:8928:a200::"))
428+
}
429+
}
430+
--- request
431+
GET /t
432+
--- no_error_log
433+
[error]
434+
--- response_body
435+
true
436+
true
437+
true
438+
true
439+
false

0 commit comments

Comments
 (0)