mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Fix lint issues in util
Reduce execution time of ConvertComponentIdIntoFriendlyPathSearch by 50-60% and add benchmark Signed-off-by: Nicholas Jackson <nickajacks1@gmail.com>
This commit is contained in:
@@ -565,7 +565,8 @@ func IsHttpVerb(verb string) bool {
|
||||
}
|
||||
|
||||
// define bracket name expression
|
||||
var bracketNameExp = regexp.MustCompile("^(\\w+)\\[(\\w+)\\]$")
|
||||
var bracketNameExp = regexp.MustCompile(`^(\w+)\[(\w+)\]$`)
|
||||
var pathCharExp = regexp.MustCompile(`[%=;~.]`)
|
||||
|
||||
func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
|
||||
segs := strings.Split(id, "/")
|
||||
@@ -574,8 +575,7 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
|
||||
|
||||
// check for strange spaces, chars and if found, wrap them up, clean them and create a new cleaned path.
|
||||
for i := range segs {
|
||||
pathCharExp, _ := regexp.MatchString("[%=;~.]", segs[i])
|
||||
if pathCharExp {
|
||||
if pathCharExp.Match([]byte(segs[i])) {
|
||||
segs[i], _ = url.QueryUnescape(strings.ReplaceAll(segs[i], "~1", "/"))
|
||||
segs[i] = fmt.Sprintf("['%s']", segs[i])
|
||||
if len(cleaned) > 0 {
|
||||
@@ -613,11 +613,9 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
|
||||
_, err := strconv.ParseInt(name, 10, 32)
|
||||
var replaced string
|
||||
if err != nil {
|
||||
replaced = strings.ReplaceAll(fmt.Sprintf("%s",
|
||||
strings.Join(cleaned, ".")), "#", "$")
|
||||
replaced = strings.ReplaceAll(strings.Join(cleaned, "."), "#", "$")
|
||||
} else {
|
||||
replaced = strings.ReplaceAll(fmt.Sprintf("%s",
|
||||
strings.Join(cleaned, ".")), "#", "$")
|
||||
replaced = strings.ReplaceAll(strings.Join(cleaned, "."), "#", "$")
|
||||
}
|
||||
|
||||
if len(replaced) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user