From 9555492add7ae0608fa1c5f50ae1acd07430a54f Mon Sep 17 00:00:00 2001 From: Michael Peterson Date: Thu, 17 Aug 2023 10:52:02 -0700 Subject: [PATCH] Added additional regex to address internal extra dots in hostnames --- purell.go | 2 ++ purell_test.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/purell.go b/purell.go index 74c8272..3b086ce 100644 --- a/purell.go +++ b/purell.go @@ -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. @@ -368,6 +369,7 @@ func removeUnncessaryHostDots(u *url.URL) { u.Host += matches[2] } } + u.Host = rxHostInteriorDots.ReplaceAllString(u.Host, ".") } } diff --git a/purell_test.go b/purell_test.go index efde722..a1264a9 100644 --- a/purell_test.go +++ b/purell_test.go @@ -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",