Skip to content

Commit

Permalink
change: invalidate addresses that start with a period
Browse files Browse the repository at this point in the history
According to RFC 3696 (https://tools.ietf.org/html/rfc3696):
> Without quotes, local-parts may consist of any combination of
> alphabetic characters, digits, or any of the special characters
> ! # $ % & ' * + - / = ? ^ _ ` . { | } ~
> period (".") may also appear, but may not be used to start or end the
> local part, nor may two or more consecutive periods appear. Stated
> differently, any ASCII graphic (printing) character other than the
> at-sign ("@"), backslash, double quote, comma, or square brackets may
> appear without quoting. If any of that list of excluded characters
> are to appear, they must be quoted.
  • Loading branch information
ianbayne committed Oct 15, 2020
1 parent 3ff4c92 commit 7258a12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def valid?
!domain.start_with?('-') &&
!domain.include?('-.') &&
!address.local.include?('..') &&
!address.local.end_with?('.')
!address.local.end_with?('.') &&
!address.local.start_with?('.')
else
false
end
Expand Down
5 changes: 5 additions & 0 deletions spec/valid_email2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class TestUserMultiple < TestModel
expect(user.valid?).to be_falsey
end

it "is invalid if the address starts with a dot" do
user = TestUser.new(email: "[email protected]")
expect(user.valid?).to be_falsey
end

it "is invalid if the email contains emoticons" do
user = TestUser.new(email: "foo🙈@gmail.com")
expect(user.valid?).to be_falsy
Expand Down

0 comments on commit 7258a12

Please sign in to comment.