diff --git a/lib/resty/radixtree.lua b/lib/resty/radixtree.lua index 5be3463..5cf81bf 100644 --- a/lib/resty/radixtree.lua +++ b/lib/resty/radixtree.lua @@ -205,6 +205,9 @@ local mt = { __index = _M, __gc = gc_free } local function sort_route(route_a, route_b) if route_a.priority == route_b.priority then + if route_a.path_org == route_b.path_org then + return (route_a.vars_len or 0) > (route_b.vars_len or 0) + end return #route_a.path_org > #route_b.path_org end return (route_a.priority or 0) > (route_b.priority or 0) @@ -438,6 +441,7 @@ local function common_route_data(path, route, route_opts, global_opts) error("failed to handle expression: " .. err, 2) end route_opts.vars = route_expr + route_opts.vars_len = #route.vars end local hosts = route.hosts diff --git a/t/vars.t b/t/vars.t index 8e5a7a8..1822a99 100644 --- a/t/vars.t +++ b/t/vars.t @@ -566,3 +566,38 @@ metadata /aa metadata /aa nil nil + + + +=== TEST 20: match max vars condition +--- config + location /t { + content_by_lua_block { + local radix = require("resty.radixtree") + local rx = radix.new({ + { + paths = {"/aa"}, + metadata = "metadata /aa", + vars = { + {"arg_k", "==", "v"}, + }, + }, + { + paths = {"/aa"}, + metadata = "metadata /aa2", + vars = { + {"arg_k", "==", "v"}, + {"arg_k2", "==", "v2"}, + }, + }, + }) + + ngx.say(rx:match("/aa", {vars = ngx.var})) + } + } +--- request +GET /t?k=v&k2=v2 +--- no_error_log +[error] +--- response_body +metadata /aa2