From 18fba4ba8a4e56e4ed5eed7bcd09f4329caa9c05 Mon Sep 17 00:00:00 2001 From: amiraliucsc Date: Sun, 19 Apr 2020 05:22:13 +0000 Subject: [PATCH 1/3] Fix the regex for RFC952 hostname validator Signed-off-by: amiraliucsc --- regexes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regexes.go b/regexes.go index b8bf253..466eb80 100644 --- a/regexes.go +++ b/regexes.go @@ -36,7 +36,7 @@ const ( latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$" longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" sSNRegexString = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$` - hostnameRegexStringRFC952 = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952 + hostnameRegexStringRFC952 = `^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952 hostnameRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123 btcAddressRegexString = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$` // bitcoin address btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32 From 1611f1e72c15a2946d12035bf44c103c0a97f9d3 Mon Sep 17 00:00:00 2001 From: amiraliucsc Date: Sun, 19 Apr 2020 06:17:28 +0000 Subject: [PATCH 2/3] Add test regarding multiple dots in hostname Signed-off-by: amiraliucsc --- validator_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/validator_test.go b/validator_test.go index 2e4215f..32d2062 100644 --- a/validator_test.go +++ b/validator_test.go @@ -7896,6 +7896,9 @@ func TestHostnameRFC952Validation(t *testing.T) { {"2001:cdba:0000:0000:0000:0000:3257:9652", false}, {"2001:cdba:0:0:0:0:3257:9652", false}, {"2001:cdba::3257:9652", false}, + {"example..........com", false}, + {"1234", false}, + {"abc1234", true}, } validate := New() From c7dc8812a2a9ecef03a5b3e59c1801a4442a6a90 Mon Sep 17 00:00:00 2001 From: amiraliucsc Date: Sun, 19 Apr 2020 18:44:55 +0000 Subject: [PATCH 3/3] Add more tests Signed-off-by: amiraliucsc --- validator_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/validator_test.go b/validator_test.go index 32d2062..68e8132 100644 --- a/validator_test.go +++ b/validator_test.go @@ -7899,6 +7899,8 @@ func TestHostnameRFC952Validation(t *testing.T) { {"example..........com", false}, {"1234", false}, {"abc1234", true}, + {"example. com", false}, + {"ex ample.com", false}, } validate := New()