Skip to content

Fix: Support Unicode characters in email local part - #603

Open
ftoucch wants to merge 6 commits into
FGRibreau:masterfrom
ftoucch:fix/unicode-local-part-email-validation
Open

Fix: Support Unicode characters in email local part #603
ftoucch wants to merge 6 commits into
FGRibreau:masterfrom
ftoucch:fix/unicode-local-part-email-validation

Conversation

@ftoucch

@ftoucch ftoucch commented May 5, 2026

Copy link
Copy Markdown
Contributor

Fix: Support Unicode characters in email local part (#457)

Problem

MailChecker.isValid("joemartínez@google.com") was returning false for 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

  • Regex — Added \p{L} (Unicode letters) and \p{N} (Unicode digits) to the two character classes in the local part of the regex in gen.js. This is the source of truth that generates platform files.
  • JavaScript/Node.js — Added u flag to the generated regex literal to enable Unicode property support.
  • Elixir — Added u flag to the regex in the template.
  • Python — Switched from import re to import regex as re as Python's built-in re module does not support \p{L}.
  • PHP — Replaced filter_var(FILTER_VALIDATE_EMAIL) with a preg_match using the shared regex with \z and iu flags. Moved MailChecker.php to a template so the regex is generated consistently with other platforms.
  • Go/Clojure — No changes needed as their regex engines support Unicode properties natively.
  • Docker (package.json) — Fixed test:python and test:python3 commands to wrap commands in sh -c, install gcc musl-dev for Alpine builds, and pin regex==2021.11.10 for Python 2.7 compatibility.

Tests added

Added tëst@gmail.com to 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

@FGRibreau

Copy link
Copy Markdown
Owner

Interesting, what's your use-case for such change?

@ftoucch

ftoucch commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 regex module (since stdlib re doesn’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.

Comment thread platform/python/MailChecker.tmpl.py Outdated
Comment thread platform/php/blacklist.php
Comment thread test/platform.ruby.test.rb
@ftoucch

ftoucch commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@FGRibreau I made the changes suggested by Copilot in the updated pull request

@ftoucch

ftoucch commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@FGRibreau any update on this pull request

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.

í is not considered a valid character in the email address

3 participants