Skip to content

[CS-1425] Handle email addresses with spaces in local part - #38

Merged
grantspeelman merged 4 commits into
mainfrom
devin/1769164094-email-space-handling
Jan 23, 2026
Merged

grantspeelman merged 4 commits into
mainfrom
devin/1769164094-email-space-handling

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor

ixes handling of email addresses with a period followed by a space in the local part
(e.g., g. speel@example.com).

The Mail gem silently fails when parsing this specific pattern - it sets local to nil
without raising an error. This change adds validation to detect when the Mail gem can't
determine the local part and properly marks such addresses as exceptional.

What changed:

  • Added validation in initialize to raise ArgumentError when @mail_address.local is nil
    for non-blank addresses
  • Added ArgumentError rescue in cast methods to convert these to ExceptionalValue
  • Added test coverage for the period+space edge case and quoted spaces (which are valid
    per RFC 5322)

This ensures the edge case is caught early rather than silently passing through with
incomplete parsing.

Devin session: https://app.devin.ai/sessions/7c98f21a4e8a404c9febed036f9b9820
Requested by: Grant

- Add support for unquoted spaces (e.g., 'g speel@example.com') that are
  marked as exceptional but still allow domain extraction
- Add support for quoted spaces (e.g., '"g speel"@example.com') that
  remove quotes in to_s and are marked as exceptional
- Bump version to 2.0.6

Co-Authored-By: Grant <grantspeelman@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@grantspeelman grantspeelman self-assigned this Jan 23, 2026
@grantspeelman grantspeelman changed the title Handle email addresses with spaces in local part [CS-1425] Handle email addresses with spaces in local part Jan 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes handling of email addresses containing spaces in the local part by adding validation to detect when the Mail gem fails to parse the local portion. When an email like g. speel@example.com is provided, the Mail gem silently sets local to nil without raising an error, which this change now catches and converts to an ExceptionalValue.

Changes:

  • Added validation in EmailAddress#initialize to raise ArgumentError when local part is nil for non-blank addresses
  • Updated cast methods in both EmailAddress and DisplayNameEmailAddress to rescue ArgumentError and convert to ExceptionalValue
  • Added comprehensive test coverage for unquoted spaces, period+space combinations, and valid quoted spaces

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/rails_values/email_address.rb Added nil local part validation and ArgumentError rescue in cast method
lib/rails_values/display_name_email_address.rb Added ArgumentError rescue in cast method for consistency
spec/rails_values/email_address_spec.rb Added test cases for space handling edge cases
rails_values.gemspec Bumped version to 2.0.6
CHANGELOG.md Documented the email address space handling fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/rails_values/email_address_spec.rb Outdated
@grantspeelman
grantspeelman requested a review from wethu January 23, 2026 11:54
@grantspeelman
grantspeelman enabled auto-merge (squash) January 23, 2026 11:54
@grantspeelman
grantspeelman requested review from richardchou-nexl and removed request for wethu January 23, 2026 11:56
@grantspeelman
grantspeelman merged commit 66a0c8e into main Jan 23, 2026
9 checks passed
@grantspeelman
grantspeelman deleted the devin/1769164094-email-space-handling branch January 23, 2026 12:29
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.

3 participants