-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add alphaspace validator #1343
base: master
Are you sure you want to change the base?
Add alphaspace validator #1343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
|
||
const ( | ||
alphaRegexString = "^[a-zA-Z]+$" | ||
alphaSpaceRegexString = "^[a-zA-Z ]+$" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better for the regex to not match if the input contains only spaces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave it like that But people already asked for what you suggest, so I don't know But then, should leading and trailing space are valid?
I'm asking because the regexp will need to be adapted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I reviewed #1191 (comment) before asking the question. My question was more for clarification to ensure we’re aligned on the intended behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the validator should do what it says and nothing else. If a string contains any of the alpha characters or an empty space it should be valid. Anything about spaces before or after should then be dealt with by the user IMO. Unless someone can give a great example why |
||
alphaNumericRegexString = "^[a-zA-Z0-9]+$" | ||
alphaUnicodeRegexString = "^[\\p{L}]+$" | ||
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$" | ||
|
@@ -92,6 +93,7 @@ func lazyRegexCompile(str string) func() *regexp.Regexp { | |
|
||
var ( | ||
alphaRegex = lazyRegexCompile(alphaRegexString) | ||
alphaSpaceRegex = lazyRegexCompile(alphaSpaceRegexString) | ||
alphaNumericRegex = lazyRegexCompile(alphaNumericRegexString) | ||
alphaUnicodeRegex = lazyRegexCompile(alphaUnicodeRegexString) | ||
alphaUnicodeNumericRegex = lazyRegexCompile(alphaUnicodeNumericRegexString) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit annoyed, this could lead to obesity
I mean, someone will then ask for alphanumspace, alphaunicodespace, and so on
The regexps are computed by the lib even if no one use it, so lib becomes slower and slower.
The PR addresses the issue raised. So it's OK.
But I would like to step out a bit.
The regexp rule idea was already declined, for good reasons
So I think the way to consider doing this is via the custom validator
#1191 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccoVeille
Thank you for your detailed feedback. I understand and agree your concerns regarding the potential growth and its impact on library performance.
If you feel a custom validator is the better path for this functionality, I’m happy to close this pull request if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a random Gopher,user of the lib
Let's wait for a maintainer's feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I mistakenly thought you were the maintainer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the regex's are lazy loaded, so if anyone doesn't use them, it doesn't affect them as much.
In this case if people think this is a good addition, I don't think we should block it because we worry about it not being used and slightly bigger binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your explanation