Skip to content

Commit

Permalink
Fix allowed symbols in atom-text
Browse files Browse the repository at this point in the history
'@' symbols and other invalid characters were being allowed due to a faulty regexp

Fixes #86
  • Loading branch information
alexdunae committed Aug 3, 2022
1 parent d78a5e7 commit fee0236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/validates_email_format_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ def self.load_i18n_locales

require "resolv"

ATEXT_SYMBOLS = /[!\#$%&'*\-\/=?+\^_`{|}~]/

# Characters that are allowed in to appear in the local part unquoted
# https://www.rfc-editor.org/rfc/rfc5322#section-3.4.1
# https://www.rfc-editor.org/rfc/rfc5322#section-3.2.3
#
# An addr-spec is a specific Internet identifier that contains a
# locally interpreted string followed by the at-sign character ("@",
Expand All @@ -23,9 +21,13 @@ def self.load_i18n_locales
# string form SHOULD NOT be used. Comments and folding white space
# SHOULD NOT be used around the "@" in the addr-spec.
#
# atext = ALPHA / DIGIT /
# "!" / "#" / "$" / "%" / "&" / "'" / "*" /
# "+" / "-" / "/" / "=" / "?" / "^" / "_" /
# "`" / "{" / "|" / "}" / "~"
# dot-atom-text = 1*atext *("." 1*atext)
# dot-atom = [CFWS] dot-atom-text [CFWS]
ATEXT = /\A[A-Z0-9#{ATEXT_SYMBOLS}]\z/i
ATEXT = /\A[A-Z0-9!\#$%&'*\-\/=?+\^_`{|}~]\z/i

# Characters that are allowed to appear unquoted in comments
# https://www.rfc-editor.org/rfc/rfc5322#section-3.2.2
Expand Down
1 change: 1 addition & 0 deletions spec/validates_email_format_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def self.model_name

[
"no_at_symbol",
"multiple@at@symbols.com",
"invalid@example-com",
# period can not start local part
".invalid@example.com",
Expand Down

0 comments on commit fee0236

Please sign in to comment.