-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
test(git): relax email validation in commitEntry results #1876
test(git): relax email validation in commitEntry results #1876
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #1876 +/- ##
=======================================
Coverage 99.62% 99.63%
=======================================
Files 2357 2357
Lines 236856 236856
Branches 1228 1229 +1
=======================================
+ Hits 235973 235991 +18
+ Misses 861 843 -18
Partials 22 22 |
Lets discuss in a meeting if hyphens are valid or at least common enough to be considered as generate-able inside a |
if they are valid in faker.internet.email(), they should also be valid as part of an email address in commitEntry |
Or we remove that in email function as well The implementation is still from v5.5.3 and not written by the new maintainers |
I think we can easily test this by using https://github.com/validatorjs/validator.js/blob/master/src/lib/isEmail.js once. |
Hyphens are allowed in email addresses through some providers like gmail don't allow registering usernames including a - |
We have another report about "email not valid" I start to feel more and more unsafe about our current email implementation and we should think about to prevent such cases directly inside the email function. |
Perhaps could deprecate |
It's not fully out of scope, but affected by a side-effect faker/src/modules/git/index.ts Line 120 in 59157a4
Here we don't pass any options to the email function ... its getting even madder 👀 faker/src/modules/internet/index.ts Lines 96 to 98 in 59157a4
why does the |
I dislike the current allowSpecialCharacters implementation. It's weird which is why I haven't touched it! |
AllowSpecialCharacters is really "substitute some random special chars in which may break things in interesting ways" which is almost certainly never desirable. |
@matthewmayer don't get me wrong, I'm thankful that you bring this forward and are patient to this |
understood, though note this blocks #1872. Non-english locales already generate emails with hyphens in them, its just that the tests only check this in |
So i think there are really two discussions
Once that's decided, the regexes for testing in faker.internet.email and faker.git.commitEntry should be aligned
|
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.
Looks like we forgot to actually post our decision on this PR.
Team Decision
Instead of using a custom regex, that might fail with any refactor, we should grep the email address from that line and check it with validatorjs.isEmail.
The validator function has an option require_display_name
, that can be used to require it to have a display name like the commit entry has.
expect(parts[n]).toMatch(/^Author: .*$/);
expect(parts[n].substring(8)).toSatisfy(v -> isEmail(v, { require_display_name: true }));
We also discussed changing the email function:
but how are you gonna extract the email address from the line without using a regex in the first place :D |
As written above (using expect(parts[n]).toMatch(/^Author: .*$/);
expect(parts[n].substring(8)).toSatisfy(v -> isEmail(v, { require_display_name: true })); |
8597439
Any idea why the tests fail? Did I make a mistake with the require_display_name part? |
it appears dots in the display name fail the validator. it expects them to be quoted.
|
it seems git doesnt follow the exact same rules as display names for email addresses per RFC 5322 For example i can run
and then in git log commits show without quoting the display name, although those would be required by RFC 5322 |
I think for our purposes it is enough if we modify that part to always include the quotes. x.replace(/^(.*) </, '"$1" <') Would that work? |
You mean replace it in the test? Or replace what commitEntry produces? |
Yes, only in the test as the git output seems to omit the quotes. |
extracted from #1872
the test for email addresses in the commitEntry test is stricter than what is allowed for faker.internet.email(), specifically hyphens are not allowed. This changes the regex to match that used for stripping the localPart in faker.internet.email().