File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ local function transform_pattern(path)
57
57
if string.match (match , ' ^.' ) ~= ' /' then
58
58
match = ' /' .. match
59
59
end
60
- match = ' ^' .. match .. ' $'
60
+ match = ' ^( ' .. match .. ' ) $'
61
61
end
62
62
63
63
return match , stash
@@ -70,9 +70,14 @@ local function matches(r, filter)
70
70
end
71
71
72
72
local regex_groups_matched = {string.match (filter .path , r .match )}
73
+
73
74
if # regex_groups_matched == 0 then
74
75
return false
75
76
end
77
+
78
+ -- first regex_group is whole path, we should omit it
79
+ table.remove (regex_groups_matched , 1 )
80
+
76
81
if # r .stash > 0 and # r .stash ~= # regex_groups_matched then
77
82
return false
78
83
end
@@ -86,7 +91,6 @@ local function matches(r, filter)
86
91
return true , {
87
92
route = r ,
88
93
stash = regex_groups_matched ,
89
-
90
94
-- the more symbols were known in advance by route,
91
95
-- the more priority we give the route
92
96
specificity = - symbols_didnt_know ,
Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ g.after_each(function()
16
16
g .server :stop ()
17
17
end )
18
18
19
+ g .test_route_priority_any = function ()
20
+ g .router :route ({ path = ' test/*any' , method = ' GET' }, function () return {body = ' any' } end )
21
+ t .assert_equals (http_client .get (helper .base_uri .. ' test/some' ).body , ' any' )
22
+
23
+ g .router :route ({ path = ' test/some' , method = ' GET' }, function () return {body = ' some' } end )
24
+ t .assert_equals (http_client .get (helper .base_uri .. ' test/some' ).body , ' some' )
25
+ end
26
+
19
27
g .test_route_priority_stash = function ()
20
28
g .router :route ({method = ' GET' , path = ' *stashname' }, function (_ )
21
29
return {
You can’t perform that action at this time.
0 commit comments