mirror of https://github.com/gofiber/fiber.git
♻️ Refactor: replace isInCharset with bytes.IndexByte (#3342)
parent
4177ab4086
commit
600ebd95ce
2
ctx.go
2
ctx.go
|
@ -1349,7 +1349,7 @@ func (c *DefaultCtx) getLocationFromRoute(route Route, params Map) (string, erro
|
||||||
|
|
||||||
for key, val := range params {
|
for key, val := range params {
|
||||||
isSame := key == segment.ParamName || (!c.app.config.CaseSensitive && utils.EqualFold(key, segment.ParamName))
|
isSame := key == segment.ParamName || (!c.app.config.CaseSensitive && utils.EqualFold(key, segment.ParamName))
|
||||||
isGreedy := segment.IsGreedy && len(key) == 1 && isInCharset(key[0], greedyParameters)
|
isGreedy := segment.IsGreedy && len(key) == 1 && bytes.IndexByte(greedyParameters, key[0]) != -1
|
||||||
if isSame || isGreedy {
|
if isSame || isGreedy {
|
||||||
_, err := buf.WriteString(utils.ToString(val))
|
_, err := buf.WriteString(utils.ToString(val))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
13
path.go
13
path.go
|
@ -7,6 +7,7 @@
|
||||||
package fiber
|
package fiber
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -308,7 +309,7 @@ func (routeParser *routeParser) analyseParameterPart(pattern string, customConst
|
||||||
parameterEndPosition = 0
|
parameterEndPosition = 0
|
||||||
case parameterEndPosition == -1:
|
case parameterEndPosition == -1:
|
||||||
parameterEndPosition = len(pattern) - 1
|
parameterEndPosition = len(pattern) - 1
|
||||||
case !isInCharset(pattern[parameterEndPosition+1], parameterDelimiterChars):
|
case bytes.IndexByte(parameterDelimiterChars, pattern[parameterEndPosition+1]) == -1:
|
||||||
parameterEndPosition++
|
parameterEndPosition++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,16 +398,6 @@ func (routeParser *routeParser) analyseParameterPart(pattern string, customConst
|
||||||
return n, segment
|
return n, segment
|
||||||
}
|
}
|
||||||
|
|
||||||
// isInCharset check is the given character in the charset list
|
|
||||||
func isInCharset(searchChar byte, charset []byte) bool {
|
|
||||||
for _, char := range charset {
|
|
||||||
if char == searchChar {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// findNextCharsetPosition search the next char position from the charset
|
// findNextCharsetPosition search the next char position from the charset
|
||||||
func findNextCharsetPosition(search string, charset []byte) int {
|
func findNextCharsetPosition(search string, charset []byte) int {
|
||||||
nextPosition := -1
|
nextPosition := -1
|
||||||
|
|
Loading…
Reference in New Issue