From cf5769cbfcf8352009413d8ef4c33ec64bb50841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E4=B8=96=E5=B9=B3?= Date: Wed, 1 Jul 2020 16:08:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=BD=BF=E7=94=A8lua?= =?UTF-8?q?=E5=86=85=E7=BD=AE=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=B2?= =?UTF-8?q?=E5=88=87=E5=89=B2=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?openresty=E8=87=AA=E5=B8=A6=E7=9A=84ngx.re.split=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD=E5=92=8C?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=98=85=E8=AF=BB=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/tools.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lua/tools.lua b/lua/tools.lua index 40e4f75..513e9aa 100644 --- a/lua/tools.lua +++ b/lua/tools.lua @@ -1,11 +1,25 @@ module("tools", package.seeall) +local ngx_re = require "ngx.re" + function split(s, p) -- 字符串切割 local rt = {} - string.gsub(s, '[^' .. p .. ']+', function(w) - rt[#rt + 1] = w - --table.insert(rt, w) - end ) + + -- 对问号分割做转义 + if p == "?" then + p = "\\?" + end + + local res = ngx_re.split(s, p) + if res then + if res[1] == "" then + table.remove(res, 1) + end + rt = res + else + table.insert(rt, 1, s) + end + return rt end From 570b26c6ff7af4264b4c16ed13b5f44ec8626c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E4=B8=96=E5=B9=B3?= Date: Wed, 1 Jul 2020 16:22:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/upstream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/upstream.lua b/lua/upstream.lua index e3857b8..07c953d 100644 --- a/lua/upstream.lua +++ b/lua/upstream.lua @@ -21,7 +21,7 @@ function _M.set(real_new_uri) for i, elem in ipairs(rewrite_conf[host]['rewrite_urls']) do --local ret = tools.match(uri,elem['uri']) --if ret then - local ret = tools.match('/'..svc_code,elem['uri']) + -- local ret = tools.match('/'..svc_code,elem['uri']) if '/'..svc_code == elem['uri'] then data [string.len(elem['uri'])] = elem['rewrite_upstream'] end