fix: reject hostnames with trailing hyphen in RFC 952 validator - #1569
Merged
zemzale merged 1 commit intoApr 29, 2026
Merged
Conversation
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]>
nodivbyzero
approved these changes
Apr 28, 2026
1 task
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
@go-playground/validator-maintainers