Skip to content

Conversation

@nlevchuk
Copy link
Contributor

@nlevchuk nlevchuk commented Nov 7, 2024

First of all, I'd like to thank all the contributors for their time and effort.

Recently, I've noticed that the EMAIL_REGEXP constant fails to handle a situations where there are leading or trailing dots in the local part of an email address. It's worth noting that while all major email providers permit the use of dots between characters, they prohibit their placement at the beginning or end of the local part.
I didn't find the exact information about the leading and trailing dots in the RFCs (5321, 5322). However, I believe it's practically useful to specify them in the regex.

Examples of an invalid email:

  • .hello@example.com
  • hello.@example.com

@nobu nobu merged commit 788274b into ruby:master Jul 12, 2025
24 checks passed
Comment on lines 53 to 54
# practical regexp for email address
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
Copy link
Member

Choose a reason for hiding this comment

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

It was unfortunate that there was no test cases to assert intentional violations to work, but as clearly mentioned in this comment right above the updated regexp, the leading/trailing/consecutive dots are intentionally allowed - otherwise it is considered a major breaking change. #189 (comment)

@sorah
Copy link
Member

sorah commented Nov 4, 2025

Replicating #177 (comment)

Quickly informing that I've reverted #172 at #189 and shipped v1.1.1 as the email addresses in question were intentionally allowed - it is based on WHATWG's practical pattern, contains intentional violation against RFCs. It was mentioned in a comment but unfortunate it lacked test cases. There is a room to add RFC-strict regexp pattern under another *_REGEXP constant, but changing behaviour of the existing constant considered a bug or regression. If you need such strict patterns, please file a feature request instead.

uri/lib/uri/mailto.rb

Lines 53 to 55 in f1b05c8

# practical regexp for email address
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/

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