Skip to content

Commit b9258bd

Browse files
fix(fqdn): allow hyphens in last domain label (#1548)
## Fixes Or Enhances ## Summary The `fqdn` validator was rejecting valid domain names that contain hyphens in the last label (e.g. `test-site-http.test-site`), because the TLD character class `[a-zA-Z0-9]` did not include `-`. ## Change One character added to the last label's character class in `fqdnRegexStringRFC1123`: No other parts of the regex were modified. ## Test Added regression case to [TestFQDNValidation](cci:1://file:///Users/admin/validator/validator_test.go:10628:0-10676:1): - `test-site-http.test-site` → valid @go-playground/validator-maintainers
1 parent b9f1d79 commit b9258bd

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

regexes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
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])$`
5959
hostnameRegexStringRFC952 = `^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952
6060
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
61-
fqdnRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?$` // same as hostnameRegexStringRFC1123 but must contain a non numerical TLD (possibly ending with '.')
61+
fqdnRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9-]{0,62})\.?$` // same as hostnameRegexStringRFC1123 but must contain a non numerical TLD (possibly ending with '.')
6262
btcAddressRegexString = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$` // bitcoin address
6363
btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
6464
btcAddressLowerRegexStringBech32 = `^bc1[02-9ac-hj-np-z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32

validator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10643,6 +10643,7 @@ func TestFQDNValidation(t *testing.T) {
1064310643
{"test24.example24.com.", true},
1064410644
{"24.example24.com", true},
1064510645
{"test.24.example.com", true},
10646+
{"test-site-http.test-site", true},
1064610647
{"test24.example24.com..", false},
1064710648
{"example", false},
1064810649
{"192.168.0.1", false},

0 commit comments

Comments
 (0)