Skip to content

Commit

Permalink
cleaned backslash failure on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Jun 13, 2024
1 parent df609ab commit 40e71fd
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/url"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -589,8 +588,8 @@ func IsHttpVerb(verb string) bool {

// define bracket name expression
var (
bracketNameExp = regexp.MustCompile(`^(\w+)\['?(\w+)\'?]$`)
pathCharExp = regexp.MustCompile(`[\\%=;~.]`)
bracketNameExp = regexp.MustCompile(`^(\w+)\['?(\w+)'?]$`)
pathCharExp = regexp.MustCompile(`[%=;~.]`)
)

func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
Expand All @@ -601,21 +600,21 @@ 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 {
if pathCharExp.Match([]byte(segs[i])) {

segs[i], _ = url.QueryUnescape(strings.ReplaceAll(segs[i], "~1", "/"))
// strip out any backslashes, but only on non-windows systems.
if runtime.GOOS != "windows" && strings.Contains(id, "#") && strings.Contains(segs[i], `\`) {
segs[i] = strings.ReplaceAll(segs[i], `\`, "")
cleaned = append(cleaned, segs[i])
continue
}
segs[i] = fmt.Sprintf("['%s']", segs[i])
if len(cleaned) > 0 {
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", segs[i-1], segs[i])
continue
}
} else {

// strip out any backslashes
if strings.Contains(id, "#") && strings.Contains(segs[i], `\`) {
segs[i] = strings.ReplaceAll(segs[i], `\`, "")
cleaned = append(cleaned, segs[i])
continue

Check warning on line 615 in utils/utils.go

View check run for this annotation

Codecov / codecov/patch

utils/utils.go#L613-L615

Added lines #L613 - L615 were not covered by tests
}

// check for brackets in the name, and if found, rewire the path to encapsulate them
// correctly. https://github.com/pb33f/libopenapi/issues/112
brackets := bracketNameExp.FindStringSubmatch(segs[i])
Expand Down

0 comments on commit 40e71fd

Please sign in to comment.