From aa411e6d57e4bbe194bfe3d6033052e40b4c4604 Mon Sep 17 00:00:00 2001 From: xuruidong Date: Mon, 8 Apr 2024 22:42:10 +0800 Subject: [PATCH 1/2] fix: error occurs if the opt.vars is not passed Signed-off-by: xuruidong --- lib/resty/radixtree.lua | 2 +- t/add.t | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/resty/radixtree.lua b/lib/resty/radixtree.lua index f20e501..6e21b02 100644 --- a/lib/resty/radixtree.lua +++ b/lib/resty/radixtree.lua @@ -749,7 +749,7 @@ local function match_route_opts(route, opts, args) local len = #hosts for i = 1, len, 2 do if str_find(hosts[i+1], ":", 1, true) then - if opts.vars.http_host then + if opts.vars and opts.vars.http_host then host = opts.vars.http_host end else diff --git a/t/add.t b/t/add.t index 4046781..1b4202c 100644 --- a/t/add.t +++ b/t/add.t @@ -221,3 +221,30 @@ GET /t --- response_body pass true + + + +=== TEST 7: match failed if http_host is not passed +--- config + location /t { + content_by_lua_block { + local opts = {host = "127.0.0.1"} + local radix = require("resty.radixtree") + local rx = radix.new({ + { + paths = {"/aa*"}, + hosts = "127.0.0.1:9080", + handler = function (ctx) + ngx.say("pass") + end + } + }) + ngx.say(rx:dispatch("/aa", opts)) + } + } +--- request +GET /t +--- no_error_log +[error] +--- response_body +nil From 1680a2bbace50e5583b3f50bbf8c1d632dc910b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=91=9E=E4=B8=9C?= Date: Wed, 29 May 2024 12:11:09 +0800 Subject: [PATCH 2/2] fix(test): hosts should be array --- t/add.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/add.t b/t/add.t index 1b4202c..f56f8eb 100644 --- a/t/add.t +++ b/t/add.t @@ -233,7 +233,7 @@ true local rx = radix.new({ { paths = {"/aa*"}, - hosts = "127.0.0.1:9080", + hosts = {"127.0.0.1:9080"}, handler = function (ctx) ngx.say("pass") end