Skip to content

Commit

Permalink
🐛 bug: fix constraints when to use multiple params (#2077)
Browse files Browse the repository at this point in the history
* 🐛 bug: fix constraints when to use multiple params

* test case route matching
remove the parameters for negative routing matches, as they are unnecessary and should not be considered there

Co-authored-by: René Werner <rene@gofiber.io>
  • Loading branch information
efectn and ReneWerner87 committed Sep 8, 2022
1 parent bb10225 commit 35753f7
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 115 deletions.
14 changes: 3 additions & 11 deletions path.go
Expand Up @@ -362,23 +362,15 @@ func findLastCharsetPosition(search string, charset []byte) int {
// findNextCharsetPositionConstraint search the next char position from the charset
// unlike findNextCharsetPosition, it takes care of constraint start-end chars to parse route pattern
func findNextCharsetPositionConstraint(search string, charset []byte) int {
constraintStart := findNextNonEscapedCharsetPosition(search, parameterConstraintStartChars)
constraintEnd := findNextNonEscapedCharsetPosition(search, parameterConstraintEndChars)
nextPosition := -1
constraintStart := -1
constraintEnd := -1

for _, char := range charset {
pos := strings.IndexByte(search, char)

if char == paramConstraintStart {
constraintStart = pos
}

if char == paramConstraintEnd {
constraintEnd = pos
}

if pos != -1 && (pos < nextPosition || nextPosition == -1) {
if pos > constraintStart && pos < constraintEnd {
if (pos > constraintStart && pos > constraintEnd) || (pos < constraintStart && pos < constraintEnd) {
nextPosition = pos
}
}
Expand Down

0 comments on commit 35753f7

Please sign in to comment.