Skip to content

Commit

Permalink
fix: Falsely detecting Scandinavian characters as emojis (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspernj authored Oct 23, 2024
1 parent a06fdf7 commit e64de5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "valid_email2"
require "resolv"
require "mail"
require "unicode/emoji"

module ValidEmail2
class Address
Expand Down Expand Up @@ -34,7 +35,7 @@ def initialize(address, dns_timeout = 5, dns_nameserver = nil)
@parse_error = true
end

@parse_error ||= address_contain_emoticons? @raw_address
@parse_error ||= address_contain_emoticons?
end

def valid?
Expand Down Expand Up @@ -130,10 +131,10 @@ def mx_server_is_in?(domain_list)
}
end

def address_contain_emoticons?(email)
return false if email.nil?
def address_contain_emoticons?
return false if @raw_address.nil?

email.each_char.any? { |char| char.bytesize > 1 }
@raw_address.scan(Unicode::Emoji::REGEX).length >= 1
end

def mx_servers
Expand Down
5 changes: 5 additions & 0 deletions spec/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
address = described_class.new("foo🙈@gmail.com")
expect(address.valid?).to be false
end

it "is valid if it contains special scandinavian characters" do
address = described_class.new("jø[email protected]")
expect(address.valid?).to eq true
end
end
end
1 change: 1 addition & 0 deletions valid_email2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry"
spec.add_runtime_dependency "mail", "~> 2.5"
spec.add_runtime_dependency "activemodel", ">= 6.0"
spec.add_runtime_dependency "unicode-emoji", "~> 3.7.0"
end

0 comments on commit e64de5c

Please sign in to comment.