Skip to content

Commit

Permalink
Added additional regex to address internal extra dots in hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-peterson-cisco committed Aug 17, 2023
1 parent 83c760d commit 9555492
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 9555492

Please sign in to comment.