diff --git a/lib/valid_email2/address.rb b/lib/valid_email2/address.rb index bfcd471..734667e 100644 --- a/lib/valid_email2/address.rb +++ b/lib/valid_email2/address.rb @@ -3,6 +3,7 @@ require "valid_email2" require "resolv" require "mail" +require "unicode/emoji" module ValidEmail2 class Address @@ -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? @@ -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 diff --git a/spec/address_spec.rb b/spec/address_spec.rb index 02a14aa..0f1165e 100644 --- a/spec/address_spec.rb +++ b/spec/address_spec.rb @@ -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ørgen@email.dk") + expect(address.valid?).to eq true + end end end diff --git a/valid_email2.gemspec b/valid_email2.gemspec index b9e67a7..a8df0bc 100644 --- a/valid_email2.gemspec +++ b/valid_email2.gemspec @@ -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