From 262d798c9e003cec215b4a844675938d5b64bdca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=91=9E=E4=B8=9C?= Date: Fri, 16 Aug 2024 13:56:28 +0800 Subject: [PATCH] fix: error occurs if the opt.vars is not passed (#146) 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..f56f8eb 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