Skip to content

Commit

Permalink
fix: match route with ':'
Browse files Browse the repository at this point in the history
Fix apache#3134.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Dec 29, 2020
1 parent 45e909a commit 2fe0dcb
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apisix/control/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ do
local routes = {}
local v1_routes = {}
local function empty_func() end
local router_opts = {
no_param_match = true
}

function fetch_control_api_router()
core.table.clear(routes)
Expand Down Expand Up @@ -83,7 +86,7 @@ function fetch_control_api_router()
handler = empty_func,
})

return router.new(routes)
return router.new(routes, router_opts)
end

end -- do
Expand Down
7 changes: 5 additions & 2 deletions apisix/http/router/radixtree_host_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ end


local function empty_func() end
local router_opts = {
no_param_match = true
}


local function create_radixtree_router(routes)
Expand Down Expand Up @@ -115,11 +118,11 @@ local function create_radixtree_router(routes)
})
end
if #host_router_routes > 0 then
host_router = router.new(host_router_routes)
host_router = router.new(host_router_routes, router_opts)
end

-- create router: only_uri_router
only_uri_router = router.new(only_uri_routes)
only_uri_router = router.new(only_uri_routes, router_opts)
return true
end

Expand Down
5 changes: 4 additions & 1 deletion apisix/http/router/radixtree_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ local _M = {version = 0.2}


local uri_routes = {}
local router_opts = {
no_param_match = true
}
local uri_router
local function create_radixtree_router(routes)
routes = routes or {}
Expand Down Expand Up @@ -81,7 +84,7 @@ local function create_radixtree_router(routes)
end

core.log.info("route items: ", core.json.delay_encode(uri_routes, true))
uri_router = router.new(uri_routes)
uri_router = router.new(uri_routes, router_opts)
end


Expand Down
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = {
"lua-resty-cookie = 0.1.0",
"lua-resty-session = 2.24",
"opentracing-openresty = 0.1",
"lua-resty-radixtree = 2.5",
"lua-resty-radixtree = 2.6",
"lua-protobuf = 0.3.1",
"lua-resty-openidc = 1.7.2-1",
"luafilesystem = 1.7.0-2",
Expand Down
53 changes: 53 additions & 0 deletions t/router/radixtree-host-uri2.t
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,56 @@ qr/1981/
use config_center: yaml
--- no_error_log
[error]
=== TEST 6: set route with ':'
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/file:listReputationHistories",
"plugins":{"proxy-rewrite":{"uri":"/hello"}},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 7: hit routes
--- request
GET /file:listReputationHistories
--- response_body
hello world
--- no_error_log
[error]
=== TEST 8: not hit
--- request
GET /file:xx
--- error_code: 404
--- no_error_log
[error]
53 changes: 53 additions & 0 deletions t/router/radixtree-uri-host.t
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,56 @@ GET /hello?name=json
hello world
--- no_error_log
[error]
=== TEST 15: set route with ':'
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/file:listReputationHistories",
"plugins":{"proxy-rewrite":{"uri":"/hello"}},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 16: hit routes
--- request
GET /file:listReputationHistories
--- response_body
hello world
--- no_error_log
[error]
=== TEST 17: not hit
--- request
GET /file:xx
--- error_code: 404
--- no_error_log
[error]

0 comments on commit 2fe0dcb

Please sign in to comment.