Skip to content

Commit

Permalink
Merge pull request #38 from michael-peterson-cisco/FlagRemoveUnnecess…
Browse files Browse the repository at this point in the history
…aryHostDots-doesn't-remove-extra-dots-between-parts-#36
  • Loading branch information
JohnTitor committed Oct 22, 2023
2 parents 83c760d + 9555492 commit 1fa4a70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions purell.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var rxDWORDHost = regexp.MustCompile(`^(\d+)((?:\.+)?(?:\:\d*)?)$`)
var rxOctalHost = regexp.MustCompile(`^(0\d*)\.(0\d*)\.(0\d*)\.(0\d*)((?:\.+)?(?:\:\d*)?)$`)
var rxHexHost = regexp.MustCompile(`^0x([0-9A-Fa-f]+)((?:\.+)?(?:\:\d*)?)$`)
var rxHostDots = regexp.MustCompile(`^(.+?)(:\d+)?$`)
var rxHostInteriorDots = regexp.MustCompile(`\.+`)
var rxEmptyPort = regexp.MustCompile(`:+$`)

// Map of flags to implementation function.
Expand Down Expand Up @@ -368,6 +369,7 @@ func removeUnncessaryHostDots(u *url.URL) {
u.Host += matches[2]
}
}
u.Host = rxHostInteriorDots.ReplaceAllString(u.Host, ".")
}
}

Expand Down
7 changes: 7 additions & 0 deletions purell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ var (
"http://www.example.com/",
false,
},
{
"UnnecessaryHostDots-5",
"http://www..example...com/",
FlagsSafe | FlagRemoveUnnecessaryHostDots,
"http://www.example.com/",
false,
},
{
"EmptyPort-1",
"http://www.thedraymin.co.uk:/main/?p=308",
Expand Down

0 comments on commit 1fa4a70

Please sign in to comment.