Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 bug: fix constraints when to use multiple params #2077

Merged
merged 2 commits into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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