Reject non-ASCII whitespace in idn-email and strengthen email format tests#1268
Open
el-psy-kongroo-d wants to merge 1 commit into
Open
Conversation
…tests Follow-up to networknt#1267 applying the review suggestions: - Extract the non-ASCII-whitespace check to Strings.containsNonAsciiWhitespace and reuse it from both EmailFormat and IdnEmailFormat. - idn-email shares EmailFormat's delegation and had the same bug (a leading U+00A0 was accepted); it now rejects non-ASCII whitespace too. Adds a license header to IdnEmailFormat (it had none) and a new IdnEmailFormatTest that also verifies a non-ASCII letter is still accepted. - Strengthen EmailFormatTest: assert a quoted local part with an ASCII space ("joe bloggs"@example.com) stays valid, and generalize the negative case over U+00A0, U+2003 and U+3000. The change stays deliberately narrow (whitespace only); non-ASCII letters are still accepted in idn-email. Zero-width format characters (e.g. U+200B, U+FEFF) are out of scope and unchanged.
Contributor
Author
|
Thanks for the quick review and merge on #1267, @stevehu 🙏 This follow-up applies the suggestions from that review:
Two judgment calls I flagged in the description: I kept |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1267, applying the review suggestions from that PR.
Changes
Strings.containsNonAsciiWhitespaceand reuse it from both
EmailFormatandIdnEmailFormat(instead of a privatehelper in a single class).
IdnEmailFormatsharesEmailFormat's delegation and had thesame bug — a leading U+00A0 was accepted. It now rejects non-ASCII whitespace
too. Adds a new
IdnEmailFormatTest(which also asserts a non-ASCII letteris still accepted, since idn-email allows those) and a license header to
IdnEmailFormat, which previously had none.EmailFormatTest: assert a quoted local part with an ASCIIspace (
"joe bloggs"@example.com) stays valid, and generalize the negativecase over U+00A0, U+2003 and U+3000.
Scope
Deliberately narrow: only non-ASCII whitespace is rejected. Non-ASCII
letters remain valid (important for idn-email). Zero-width format characters
such as U+200B and U+FEFF (Unicode category Cf) are out of scope and unchanged
from previous behavior.
Notes on license headers
IdnEmailFormathad no header; the added one matches its siblingEmailFormat.java(Copyright (c) 2016 Network New Technologies Inc.).EmailFormatTest/IdnEmailFormatTestuseCopyright (c) 2025 the original author or authors, matching every other test file in the format package(
TimeFormatTest,UriFormatTest, ...). That is why the Reject non-ASCII whitespace in email format #1267 header nit wasnot switched to the main-source form — it would diverge from the test siblings.
Testing
Full test suite passes (8477 tests, 0 failures).