@@ -74,6 +74,7 @@ func NewLocationMatcher(conf *ast.Config, targetPath string) (*LocationMatcher,
7474}
7575
7676func locationTester (locationsTarget []ast.Location , targetPath string ) (* LocationMatcher , error ) {
77+ // handle exact
7778 for _ , location := range locationsTarget {
7879 if location .Modifier != EXACT {
7980 continue
@@ -88,9 +89,9 @@ func locationTester(locationsTarget []ast.Location, targetPath string) (*Locatio
8889 }
8990 }
9091
91- var bestMatch * ast.Location
92+ // handle prefix and prefix priority
93+ var bestMatch ast.Location
9294 bestLength := 0
93-
9495 for _ , location := range locationsTarget {
9596 if location .Modifier != PREFIX && location .Modifier != PREFIX_PRIORITY {
9697 continue
@@ -99,12 +100,22 @@ func locationTester(locationsTarget []ast.Location, targetPath string) (*Locatio
99100 if strings .HasPrefix (targetPath , location .Match ) {
100101 locationLength := len (location .Match )
101102 if locationLength > bestLength {
102- bestMatch = & location
103+ bestMatch = location
103104 bestLength = locationLength
104105 }
105106 }
106107 }
107108
109+ // do not go to regex if priority
110+ if bestMatch .Match != "" && bestMatch .Modifier == PREFIX_PRIORITY {
111+ return & LocationMatcher {
112+ MatchPath : bestMatch .Match ,
113+ MatchModifer : bestMatch .Modifier ,
114+ Directives : bestMatch .Directives ,
115+ }, nil
116+ }
117+
118+ // handle regex
108119 for _ , location := range locationsTarget {
109120 if location .Modifier == REGEX || location .Modifier == REGEX_NO_CASE_SENSITIVE {
110121 locationRegex := location .Match
@@ -128,7 +139,8 @@ func locationTester(locationsTarget []ast.Location, targetPath string) (*Locatio
128139 }
129140 }
130141
131- if bestMatch != nil {
142+ // use longest match
143+ if bestMatch .Match != "" {
132144 return & LocationMatcher {
133145 MatchPath : bestMatch .Match ,
134146 MatchModifer : bestMatch .Modifier ,
0 commit comments