@@ -50,6 +50,7 @@ local sort_tab = table.sort
5050local ngx_re = require (" ngx.re" )
5151local ngx_null = ngx .null
5252local empty_table = {}
53+ local str_find = string.find
5354
5455
5556setmetatable (empty_table , {__newindex = function ()
@@ -280,16 +281,21 @@ function pre_insert_route(self, path, route)
280281 end
281282
282283 route_opts .path_org = path
284+ route_opts .param = false
283285
284- local pos = string.find (path , ' :' , 1 , true )
286+ local pos = str_find (path , ' :' , 1 , true )
285287 if pos then
286288 path = path :sub (1 , pos - 1 )
287289 route_opts .path_op = " <="
288290 route_opts .path = path
291+ route_opts .param = true
289292
290293 else
291- pos = string.find (path , ' *' , 1 , true )
294+ pos = str_find (path , ' *' , 1 , true )
292295 if pos then
296+ if pos ~= # path then
297+ route_opts .param = true
298+ end
293299 path = path :sub (1 , pos - 1 )
294300 route_opts .path_op = " <="
295301 else
@@ -434,10 +440,14 @@ local function fetch_pat(path)
434440 return pat , names
435441end
436442
437- local function compare_gin (l_v , r_v , opts )
438- local pat , names = fetch_pat (r_v )
439- -- log_info("pat: ", require("cjson").encode(pat))
440- local m = re_match (l_v , pat , " jo" )
443+ local function compare_param (req_path , route , opts )
444+ if not opts .matched and not route .param then
445+ return true
446+ end
447+
448+ local pat , names = fetch_pat (route .path_org )
449+ log_info (" pcre pat: " , pat )
450+ local m = re_match (req_path , pat , " jo" )
441451 if not m then
442452 return false
443453 end
@@ -502,8 +512,8 @@ local compare_funcs = {
502512 end
503513 return false
504514 end ,
505- [" IN" ] = in_array ,
506- [" in" ] = in_array ,
515+ [" IN" ] = in_array ,
516+ [" in" ] = in_array ,
507517}
508518
509519
@@ -622,10 +632,10 @@ local function _match_from_routes(routes, path, opts, ...)
622632 if match_route_opts (route , opts , ... ) then
623633 -- log_info("matched route: ", require("cjson").encode(route))
624634 -- log_info("matched path: ", path)
625- if compare_gin (path , route . path_org , opts ) then
626- if opts_matched_exists then
627- opts .matched ._path = route .path_org
628- end
635+ if compare_param (path , route , opts ) then
636+ if opts_matched_exists then
637+ opts .matched ._path = route .path_org
638+ end
629639 return route
630640 end
631641 end
0 commit comments