Skip to content

fix: reject hostnames with trailing hyphen in RFC 952 validator - #1569

Merged
zemzale merged 1 commit into
go-playground:masterfrom
ahmedkamalio:fix/hostname-rfc952-trailing-hyphen
Apr 29, 2026
Merged

fix: reject hostnames with trailing hyphen in RFC 952 validator#1569
zemzale merged 1 commit into
go-playground:masterfrom
ahmedkamalio:fix/hostname-rfc952-trailing-hyphen

Conversation

@ahmedkamalio

Copy link
Copy Markdown
Contributor

Fixes Or Enhances

Similar to the recent fix #1565 6bcb7bc RFC 952 is now fixed to reject hostname labels with trailing hyphen

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

The previous RFC 952 hostname regex allowed labels ending with a hyphen
(e.g. "foo-.example.com"), which violates RFC 952. Replace it with a
per-label pattern matching the RFC 1123 structure but requiring a leading
letter, so each label must start and end with an alphanumeric character.

Signed-off-by: Ahmed Kamal <[email protected]>
@ahmedkamalio
ahmedkamalio requested a review from a team as a code owner April 28, 2026 00:32
@zemzale
zemzale merged commit 7c334e5 into go-playground:master Apr 29, 2026
7 checks passed
@ahmedkamalio
ahmedkamalio deleted the fix/hostname-rfc952-trailing-hyphen branch April 29, 2026 19:03
mahirhir added a commit to mahirhir/validator that referenced this pull request Aug 31, 2026
fqdnRegexStringRFC1123 matched each label with
[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62}, which allows a label to end in a
hyphen (e.g. "foo-.example.com" or "example.com-"). The hostname
validators were fixed for the same issue in go-playground#1565 (RFC 1123) and go-playground#1569
(RFC 952), but the fqdn pattern, whose comment says it should match
hostnameRegexStringRFC1123, was left behind.

Use the same label shape [a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])? so
a label must start and end with an alphanumeric. The non-numeric TLD,
the optional trailing dot, and hyphens inside the last label (go-playground#1548) are
preserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants