Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rblib/tests/validate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ def test_is_valid_email
assert(MySociety::Validate.is_valid_email("mr.example@example.com") != nil)
end

def test_unicode_localpart_is_not_valid_email
assert(MySociety::Validate.is_valid_email("Pelé@example.com") == nil)
def test_unicode_localpart_is_valid_email
assert(MySociety::Validate.is_valid_email("Pelé@example.com") != nil)
end

def test_unicode_domain_is_valid_email
assert(MySociety::Validate.is_valid_email("üñîçøðé@üñîçøðé.com") != nil)
end

def test_localpart_with_unquoted_space_is_not_valid_email
Expand Down
5 changes: 2 additions & 3 deletions rblib/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,21 @@ def self.email_match_regexp
# domain = sub-domain ("." sub-domain)* | address-literal
# sub-domain = [A-Za-z0-9][A-Za-z0-9-]*
# XXX ignore address-literal because nobody uses those...
# XXX Update this for http://tools.ietf.org/html/rfc6530
# N.B. intended for validating email addresses in their canonical form,
# so does not allow folding whitespace

specials = '()<>@,;:\\\\".\\[\\]'
controls = '\\000-\\037\\177'
# To add MacRuby support, see https://github.com/nex3/sass/pull/432
highbit = '\\u{80}-\\u{D7FF}\\u{E000}-\\u{FFFD}\\u{10000}-\\u{10FFFF}'
atext = "[^#{specials} #{controls}#{highbit}]"
atext = "[^#{specials} #{controls}]"
atom = "#{atext}+"
dot_string = "#{atom}(\\.#{atom})*"
qtext = "[^\"\\\\\\r\\n#{highbit}]"
quoted_pair = '\\.'
quoted_string = "\"(#{qtext}|#{quoted_pair})*\""
local_part = "(#{dot_string}|#{quoted_string})"
sub_domain = '[A-Za-z0-9][A-Za-z0-9-]*'
sub_domain = "#{atom}"
domain = "#{sub_domain}(\\.#{sub_domain})*"

return "#{local_part}@#{domain}"
Expand Down