-
Notifications
You must be signed in to change notification settings - Fork 798
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
Contact Form: Revised the email validation regex to include length limit #9323
Conversation
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.
LGTM! Thank you!
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.
This is not validating properly.
It's even checking for literal spaces right now: https://regex101.com/r/MAOFqc/4
var newRe = /(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}\z) (?=[a-z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@) [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)* @ (?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+ (?=[a-z0-9-]{1,63}\z)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
var oldRe = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
newRe.test( '[email protected]' );
false
oldRe.test( '[email protected]' );
true
When I tested, I made a mistake and tested with the minified version (which doesn't include the changes proposed here)
I think I got what was causing the issues. The regex was correct but two things must be done to apply it to javascript, due to regex flavors: 1.) The For the previous regex on the website, there were only Unlike the previous regex, the latest regex version on the website (the very bottom one) not only has 2.) The pink-colored white spaces in the middle of regex must also be removed, which was part of web page layout. In the previous regex, there were no white space that need to be removed. I've push a new commit with the revised regex. ===== Tests: [email protected] local part (64 char.): local part (65 char.): part of domain (63 char.): part of domain (64 char.): total length (254 char.): https://regex101.com/r/AZTNg9/6 |
@stevenlin-x can you please clarify in this PR's description which expression is the one you're taking as appropriate from https://www.regular-expressions.info/email.html and then, right next to it, the JS version you're implementing. Some time has passed and there's a lot of regex translation happening |
I've added the regex of both PHP and JS versions to the PR description. |
This comment has been minimized.
This comment has been minimized.
I played a bit with this PR. I made a simple jsFiddle with some valid and invalid emails according to Wiki and this post https://jsfiddle.net/f9dkotb8/1/ Here are the results:
@stevenlin-x do you think we should cover these failing cases too? |
FWIW: I looked into ways to cover this change with unit-tests. Unfortunately, it's not easy(or even possible) to write tests for a specific function for this file due to its structure. We might want to refactor it to make sure every function is testable. |
1.) In other words, you didn't read the context of the ticket in full. 2.) The present regex in use was derived from Issue #3734 pointed out the regex no longer matches the one on the updated page. So I simply updated to reflect the character length limits. 3.) Or even better, provide the regex you would use. |
This PR has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |
Caution: This PR has changes that must be merged to WordPress.com |
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.
Apologies for the massive delay on this one. While there are other regex things to improve to ensure that all valid e-mails are accepted and all invalid are excluded, this is a step improvement and we shouldn't let perfect be the enemy of good.
Approving and open to future PRs to address the other issues (or investigate using browser-based HTML5 validation instead of the JS solution).
stevenlin-x, Your synced wpcom patch D33713-code has been updated. |
* 7.9: Changelog * Update version number * Update stable tag and tested up to * Changelog: add #13530 * changelog: add #13578 * Changelog: add #13598 * Changelog: add entry for numerous block preview changes * Changelog: add #13599 * changelog: add #13541 * Changelog: add #13542 * Changelog: add #13331 * Changelog: add #13558 * Changelog: add #13409 * Changelog: add #13582 * Changelog: add #13600 * Changelog: add #13601 * Changelog: add #13595 * Changelog: add #12695 * Changelog: add #13009 * Changelog: add #13649 * Changelog: add #13450 * Changelog: add #13507 * Changelog: add #13658 * Changelog: add #13687 * changelog: add #13683 * Changelog: add #9323 * Changelog: add #13681 * Fix typos in readme * Add link to WordPress Beta Tester plugin * Changelog: add #13630 * Changelog: add #13695 * Changelog: add #13659 * Changelog: add #13716 * Changelog: add #13664 * Changelog: add #13682 * Changelog: add #13362 * Changelog: add #13563 * Add testing list for #13563 * Changelog: add #13735 * Changelog: add #13752 * Changelog: add #13624 * Changelog: add #13756 * Changelog: add #13745 * Changelog: add #13728 * Changelog: add #13779 * Changelog: add #13699 * Changelog: add #13804 * Changelog: add #13761 * Changelog: add #13637 * Changelog: add #13517 * Changelog: add #13521 * Changelog: add #13729 * Testing list: add testing instructions for #13729 * Changelog: add sync changes * Changelog: add #13807 * Changelog: add #13654 * Changelog: add #13795 * Changelog: add #13801 * Changelog: add #13818 * Changelog: add #13725 * Changelog: add #13831 * Changelog: add #13516 * Testing list: add Twenty Twenty instructions * Changelog: add #13799 * Changelog: add #13805 * Changelog: add #13688 * Changelog: add #13830
Fixes #3734
Changes proposed in this Pull Request:
Revised the email validation regex to include length limit, in order to match the latest practical implementation of RFC 5322 in regular-expressions.info/email.html.
Regex used:
PHP version: the very bottom one on regular-expressions.info/email.html. The one after the sentence "...modern regex flavors aren't truly regular, so we can add length limit checks using lookahead like we did before:" Take note, the redundant pink-colored white spaces in the middle of the regex must be removed.
JavaScript version:
Testing instructions:
1.) Checkout the code in this PR on a test WP site.
2.) Use the Contact Form and enter some test data in each field.
3.) In the email field, test different email addresses that are expected to pass and fail.
4.) Use an email you've access to, submit the form and make sure you get the email.
5.) Revert the code back to its previous state.
Proposed changelog entry for your changes: