Fix: Support Unicode characters in email local part - #603
Conversation
|
Interesting, what's your use-case for such change? |
if we have an email with a character such as the í in joemartínez@google.com this will be flagged as not valid although this is a valid email. This will be true for any email with such character. I had saw a request for PR was asked of the person who opened the issue and it’s been a long time without response thought I could just do it. |
There was a problem hiding this comment.
Pull request overview
This PR updates the cross-platform MailChecker email validation logic to accept Unicode letters/digits in the email local part (before @), addressing cases like joemartínez@google.com that were previously rejected due to ASCII-only regex behavior.
Changes:
- Expand the shared email-validation regex to allow Unicode letters/digits in the local part (via Unicode property escapes) and enable the required Unicode regex modes per platform.
- Update Python’s implementation to use the third-party
regexmodule (since stdlibredoesn’t support\p{…}), and adjust Python test encoding/coverage accordingly. - Add regression tests across platforms for a Unicode local-part address (e.g.,
tëst@gmail.com).
Reviewed changes
Copilot reviewed 18 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/platform.ruby.test.rb | Adds a Unicode-local-part valid email test case. |
| test/platform.python.test.py | Adds UTF-8 encoding header and a Python-3-only Unicode-local-part valid email test case. |
| test/platform.php.test.php | Adds a Unicode-local-part valid email test case. |
| test/platform.node.test.js | Adds a Unicode-local-part valid email test case. |
| test/platform.elixir.test.exs | Adds a Unicode-local-part valid email test case. |
| test/platform.clojure.test.clj | Adds a Unicode-local-part valid email test case and adjusts formatting. |
| platform/python/MailChecker.tmpl.py | Switches Python regex engine import to regex for Unicode property support. |
| platform/php/MailChecker.tmpl.php | Introduces a PHP template using the shared regex via preg_match with Unicode flags. |
| platform/php/MailChecker.php | Replaces filter_var validation with preg_match using the shared regex and Unicode flags. |
| platform/php/blacklist.php | Updates the PHP blacklist data (large churn: additions/removals). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@FGRibreau I made the changes suggested by Copilot in the updated pull request |
|
@FGRibreau any update on this pull request |
Fix: Support Unicode characters in email local part (#457)
Problem
MailChecker.isValid("joemartínez@google.com")was returningfalsefor valid emails containing Unicode characters (e.g.í,ë,ñ) in the local part (before the@). This is because the regex used to validate email addresses only matched ASCII characters.What changed
\p{L}(Unicode letters) and\p{N}(Unicode digits) to the two character classes in the local part of the regex ingen.js. This is the source of truth that generates platform files.uflag to the generated regex literal to enable Unicode property support.uflag to the regex in the template.import retoimport regex as reas Python's built-inremodule does not support\p{L}.filter_var(FILTER_VALIDATE_EMAIL)with apreg_matchusing the shared regex with\zandiuflags. MovedMailChecker.phpto a template so the regex is generated consistently with other platforms.test:pythonandtest:python3commands to wrap commands insh -c, installgcc musl-devfor Alpine builds, and pinregex==2021.11.10for Python 2.7 compatibility.Tests added
Added
tëst@gmail.comto the valid email test cases across all platform test files to verify Unicode local part support.Note on Python 2.7
Python 2.7 has been EOL since January 2020. Unicode local part support is maintained on a best-effort basis. A separate issue should be opened to formally deprecate Python 2.7 support.
Fixes #457