Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow special characters to be matched in uri params #150

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/resty/radixtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ local function fetch_pat(path)
if first_byte == string.byte(":") then
table.insert(names, res[i]:sub(2))
-- See https://www.rfc-editor.org/rfc/rfc1738.txt BNF for specific URL schemes
res[i] = [=[([\w\-_;:@&=!',\%\$\.\+\*\(\)]+)]=]
res[i] = [=[([^\/]+)]=]

elseif first_byte == string.byte("*") then
local name = res[i]:sub(2)
Expand Down
29 changes: 29 additions & 0 deletions t/parameter.t
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,32 @@ GET /t
match meta: long
match meta: short
match meta: medium



=== TEST 14: special characters in parameter should match
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local radix = require("resty.radixtree")
local rx = radix.new({
{
paths = {"/name/:name/id"},
metadata = "metadata /name",
},
})

local opts = {matched = {}}
local meta = rx:match("/name/json%20space/id", opts)
ngx.say("match meta: ", meta)
ngx.say("matched: ", json.encode(opts.matched))
}
}
--- request
GET /t
--- no_error_log
[error]
--- response_body
match meta: metadata /name
matched: {"_path":"/name/:name/id","name":"json%20space"}
Loading