Fix email validation to prevent silent truncation with newline characters#107
Merged
afair merged 1 commit intoafair:masterfrom Oct 20, 2025
Merged
Conversation
Owner
|
Thank you! The failing build is my fault, and I have the fix for that I will apply first. I'll merge this when it is ready |
Contributor
Author
|
@afair Thanks for reviewing quickly! |
Contributor
Author
|
I re-checked it myself, and the test failed. This PR may not be good enough yet. |
- Add newline character validation in valid? method to reject emails containing \r or \n - Update test_newline_characters with comprehensive test cases - Improve test comments to clarify strip processing behavior for edge cases - Leading/trailing newlines are valid due to strip processing during initialization - Embedded newlines remain invalid as expected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6cd923b to
9bb2d80
Compare
Contributor
Author
|
I've pulled the changes from ffb5a63, re-run the tests locally, and confirmed the fix. Please review it whenever you have a moment. |
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.
Summary
Fixed a data integrity issue where email addresses containing newline characters (
\n,\r\n) were incorrectly validated astruedue to silent truncation in thesplit_local_hostmethod.Problem
The original regex
/(.+)@(.+)/would match only up to the first\ncharacter, causing silent data loss:This created a data integrity risk where invalid input appeared as valid email addresses.
Solution
Changed the regex in
split_local_hostmethod to use anchors:The
\Aand\zanchors ensure the entire string must match the email pattern. If newline characters are present, the regex fails to match, and the method returns[email, ""], causing validation to fail appropriately.Changes
Address.split_local_hostmethod (1 line change)Test Cases Added
Verification
Before fix:
After fix:
Backward Compatibility
Type of Change
Note: This fix addresses a data integrity issue where malformed input was silently truncated and incorrectly validated. The change ensures that only complete, well-formed email addresses are accepted as valid.