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 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