Skip to content

Commit

Permalink
Merge pull request #313 from erbesharat/feature/placeholer-normalize
Browse files Browse the repository at this point in the history
[path]: Normalize the path after adding it to the context
  • Loading branch information
stp-ip committed Jan 23, 2020
2 parents 0ea258a + 41425f8 commit 6854adb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions path.go
Expand Up @@ -199,11 +199,6 @@ func zoneFromPath(r *http.Request, rec record) (string, int, []string, error) {

path = fmt.Sprintf("%s?%s", path, r.URL.RawQuery)

// Normalize the path to follow RFC1034 rules
if strings.ContainsAny(path, ".") {
path = strings.Replace(path, ".", "-", -1)
}

pathSubmatchs := PathRegex.FindAllStringSubmatch(path, -1)
if rec.Re != "" {
// Compile the record regex and find path submatches
Expand All @@ -230,6 +225,7 @@ func zoneFromPath(r *http.Request, rec record) (string, int, []string, error) {

url := sortMap(unordered)
*r = *r.WithContext(context.WithValue(r.Context(), "regexMatches", unordered))
url = normalize(url)
reverse(url)
from := len(pathSlice)
url = append(url, r.Host)
Expand All @@ -245,6 +241,7 @@ func zoneFromPath(r *http.Request, rec record) (string, int, []string, error) {
if len(pathSlice) < 1 && rec.Re != "" {
return "", 0, []string{}, fmt.Errorf("custom regex doesn't work on %s", path)
}
pathSlice = normalize(pathSlice)
from := len(pathSlice)
if rec.From != "" {
fromSubmatch := FromRegex.FindAllStringSubmatch(rec.From, -1)
Expand Down Expand Up @@ -342,3 +339,15 @@ func sortMap(m map[string]string) []string {
}
return result
}

// Normalize the path to follow RFC1034 rules
func normalize(input []string) []string {
var result []string
for _, value := range input {
if strings.ContainsAny(value, ".") {
value = strings.Replace(value, ".", "-", -1)
}
result = append(result, value)
}
return result
}

0 comments on commit 6854adb

Please sign in to comment.