Skip to content

Commit c02b4e4

Browse files
fix: allow special characters to be matched in uri params (#150)
1 parent 262d798 commit c02b4e4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/resty/radixtree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ local function fetch_pat(path)
656656
if first_byte == string.byte(":") then
657657
table.insert(names, res[i]:sub(2))
658658
-- See https://www.rfc-editor.org/rfc/rfc1738.txt BNF for specific URL schemes
659-
res[i] = [=[([\w\-_;:@&=!',\%\$\.\+\*\(\)]+)]=]
659+
res[i] = [=[([^\/]+)]=]
660660

661661
elseif first_byte == string.byte("*") then
662662
local name = res[i]:sub(2)

t/parameter.t

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,32 @@ GET /t
473473
match meta: long
474474
match meta: short
475475
match meta: medium
476+
477+
478+
479+
=== TEST 14: special characters in parameter should match
480+
--- config
481+
location /t {
482+
content_by_lua_block {
483+
local json = require("toolkit.json")
484+
local radix = require("resty.radixtree")
485+
local rx = radix.new({
486+
{
487+
paths = {"/name/:name/id"},
488+
metadata = "metadata /name",
489+
},
490+
})
491+
492+
local opts = {matched = {}}
493+
local meta = rx:match("/name/json%20space/id", opts)
494+
ngx.say("match meta: ", meta)
495+
ngx.say("matched: ", json.encode(opts.matched))
496+
}
497+
}
498+
--- request
499+
GET /t
500+
--- no_error_log
501+
[error]
502+
--- response_body
503+
match meta: metadata /name
504+
matched: {"_path":"/name/:name/id","name":"json%20space"}

0 commit comments

Comments
 (0)