File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,9 @@ local mt = { __index = _M, __gc = gc_free }
204204
205205
206206local function sort_route (route_a , route_b )
207+ if route_a .priority == route_b .priority then
208+ return # route_a .path_org > # route_b .path_org
209+ end
207210 return (route_a .priority or 0 ) > (route_b .priority or 0 )
208211end
209212
Original file line number Diff line number Diff line change @@ -428,3 +428,48 @@ match meta: metadata /name
428428matched: {"_path":"/name/:name/","name":"json"}
429429match meta: nil
430430matched: []
431+
432+
433+
434+ === TEST 13: route matching for routes with params and common prefix should not be dependent on registration order
435+ --- config
436+ location /t {
437+ content_by_lua_block {
438+ local json = require("toolkit.json")
439+ local radix = require("resty.radixtree")
440+ local rx = radix.new({
441+ {
442+ paths = {"/api/:version/test/api/projects/:project_id/clusters/:cluster_id/nodes/?"},
443+ metadata = "long",
444+ },
445+ {
446+ paths = {"/api/:version/test/api/projects/:project_id"},
447+ metadata = "medium",
448+ },
449+ {
450+ paths = {"/api/:version/test/*subpath"},
451+ metadata = "short",
452+ },
453+ })
454+
455+ -- should match long
456+ local meta = rx:match("/api/v4/test/api/projects/saas/clusters/123/nodes/")
457+ ngx.say("match meta: ", meta)
458+
459+ -- should match short
460+ local meta = rx:match("/api/v4/test/api")
461+ ngx.say("match meta: ", meta)
462+
463+ -- should match medium
464+ local meta = rx:match("/api/v4/test/api/projects/saas")
465+ ngx.say("match meta: ", meta)
466+ }
467+ }
468+ --- request
469+ GET /t
470+ --- no_error_log
471+ [error]
472+ --- response_body
473+ match meta: long
474+ match meta: short
475+ match meta: medium
You can’t perform that action at this time.
0 commit comments