Skip to content

Commit

Permalink
fix: wildcard needs to match newline (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Jul 7, 2021
1 parent 61b2fc7 commit 776e155
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/resty/radixtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ local function fetch_pat(path)
name = ":ext"
end
table.insert(names, name)
res[i] = [=[(.*)]=]
-- '.' matches any character except newline
res[i] = [=[((.|\n)*)]=]
end
end

Expand Down
48 changes: 48 additions & 0 deletions t/matched.t
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,51 @@ GET /t?k=v
[error]
--- response_body
after dispatch success get matched: {"_host":"foo.com","_method":"GET","_path":"/hello*"}



=== TEST 6: match uri with '\n'
--- config
location /t {
content_by_lua_block {
local radix = require("resty.radixtree")
local rx = radix.new({
{
paths = "*",
metadata = "OK",
},
})
local opts = {method = "GET", matched = {}}
ngx.say(rx:match("/ip\nA", opts))
}
}
--- request
GET /t
--- no_error_log
[error]
--- response_body
OK



=== TEST 7: match uri with multiple '\n'
--- config
location /t {
content_by_lua_block {
local radix = require("resty.radixtree")
local rx = radix.new({
{
paths = "*",
metadata = "OK",
},
})
local opts = {method = "GET", matched = {}}
ngx.say(rx:match("/ip\ni\ni", opts))
}
}
--- request
GET /t
--- no_error_log
[error]
--- response_body
OK

0 comments on commit 776e155

Please sign in to comment.