Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Allow subdomain to end with uppercase letter #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mhargrove
Copy link

@mhargrove mhargrove commented Nov 27, 2024

Problem

reDomain regex currently returns ErrDomain errors for is.Domain on values that should be valid, ex. ABC.com

regex for subdomain values currently allows lower & upper case alpha-num for beginning and optional middle chars, but won't match if value is longer than one char and ends with upper case, ex. aBc.com is valid but abC.com returns ErrDomain

Reference

from https://github.com/go-ozzo/ozzo-validation/blob/master/is/rules.go#L246-L249:

// Domain regex source: https://stackoverflow.com/a/7933253
// Slightly modified: Removed 255 max length validation since Go regex does not
// support lookarounds. More info: https://stackoverflow.com/a/38935027
reDomain = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-zA-Z]{1,63}| xn--[a-z0-9]{1,59})$`)

Solution

updated to include uppercase letters in relevant part of the reDomain regex, which is in line with the stackoverflow answer already linked in the above referenced code comments

@@ -246,7 +246,7 @@ var (
// Domain regex source: https://stackoverflow.com/a/7933253
// Slightly modified: Removed 255 max length validation since Go regex does not
// support lookarounds. More info: https://stackoverflow.com/a/38935027
reDomain = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-zA-Z]{1,63}| xn--[a-z0-9]{1,59})$`)
reDomain = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{1,63}| xn--[a-z0-9]{1,59})$`)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we also want to add uppercase to the idn-label part, or should that be left as-is?

ex.

Suggested change
reDomain = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{1,63}| xn--[a-z0-9]{1,59})$`)
reDomain = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{1,63}| xn--[a-zA-Z0-9]{1,59})$`)

@mhargrove mhargrove changed the title [bugfix] Update reDomain to handle uppercase letters [bugfix] Update reDomain to handle uppercase letters Nov 27, 2024
@mhargrove mhargrove changed the title [bugfix] Update reDomain to handle uppercase letters [bugfix] Update reDomain to handle subdomain ending with uppercase letter Nov 27, 2024
@mhargrove mhargrove changed the title [bugfix] Update reDomain to handle subdomain ending with uppercase letter [bugfix] Allow subdomain to end with uppercase letter Nov 27, 2024
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.

2 participants