email_address 0.1.13 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,7 +107,7 @@ module EmailAddress
107
107
  %r/^([\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+)$/i.freeze
108
108
 
109
109
  def initialize(local, config={}, host=nil)
110
- self.config = config.empty? ? EmailAddress::Config.all_settings : config
110
+ @config = config.is_a?(Hash) ? Config.new(config) : config
111
111
  self.local = local
112
112
  @host = host
113
113
  @error = @error_message = nil
@@ -130,10 +130,10 @@ module EmailAddress
130
130
  def parse(raw)
131
131
  if raw =~ /\A\"(.*)\"\z/ # Quoted
132
132
  raw = $1
133
- raw.gsub!(/\\(.)/, '\1') # Unescape
133
+ raw = raw.gsub(/\\(.)/, '\1') # Unescape
134
134
  elsif @config[:local_fix] && @config[:local_format] != :standard
135
- raw.gsub!(' ','')
136
- raw.gsub!(',','.')
135
+ raw = raw.gsub(' ','')
136
+ raw = raw.gsub(',','.')
137
137
  #raw.gsub!(/([^\p{L}\p{N}]{2,10})/) {|s| s[0] } # Stutter punctuation typo
138
138
  end
139
139
  raw, comment = self.parse_comment(raw)
@@ -226,7 +226,7 @@ module EmailAddress
226
226
  def relax
227
227
  form = self.mailbox
228
228
  form += @config[:tag_separator] + self.tag if self.tag
229
- form.gsub!(/[ \"\(\),:<>@\[\]\\]/,'')
229
+ form = form.gsub(/[ \"\(\),:<>@\[\]\\]/,'')
230
230
  form
231
231
  end
232
232
 
@@ -235,7 +235,7 @@ module EmailAddress
235
235
  form = self.mailbox
236
236
  form += @config[:tag_separator] + self.tag if self.tag
237
237
  form += "(" + self.comment + ")" if self.comment
238
- form.gsub!(/([\\\"])/, '\\\1') # Escape \ and "
238
+ form = form.gsub(/([\\\"])/, '\\\1') # Escape \ and "
239
239
  if form =~ /[ \"\(\),:<>@\[\\\]]/ # Space and "(),:;<>@[\]
240
240
  form = %Q("#{form}")
241
241
  end
@@ -388,7 +388,7 @@ module EmailAddress
388
388
  def set_error(err, reason=nil)
389
389
  @error = err
390
390
  @reason= reason
391
- @error_message = EmailAddress::Config.error_message(err)
391
+ @error_message = Config.error_message(err)
392
392
  false
393
393
  end
394
394
 
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.18"
3
3
  end
@@ -37,6 +37,11 @@ class TestAddress < Minitest::Test
37
37
  assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
38
38
  end
39
39
 
40
+ def test_google_hosted
41
+ a = EmailAddress.new("Ex.am.ple+tag@boomer.com")
42
+ assert_equal a.canonical, "ex.am.ple@boomer.com"
43
+ end
44
+
40
45
  # COMPARISON & MATCHING
41
46
  def test_compare
42
47
  a = ("User+tag@example.com")
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
- require_relative '../test_helper'
3
-
1
+ require_relative "../test_helper"
4
2
 
5
3
  class TestHost < MiniTest::Test
6
4
  def test_host
@@ -10,16 +8,16 @@ class TestHost < MiniTest::Test
10
8
  assert_equal "example", a.registration_name
11
9
  assert_equal "com", a.tld
12
10
  assert_equal "ex*****", a.munge
13
- assert_nil a.subdomains
11
+ assert_nil a.subdomains
14
12
  end
15
13
 
16
14
  def test_dns_enabled
17
15
  a = EmailAddress::Host.new("example.com")
18
16
  assert_instance_of TrueClass, a.dns_enabled?
19
- old_setting = EmailAddress::Config.setting(:host_validation)
20
- EmailAddress::Config.configure(host_validation: :off)
17
+ a = EmailAddress::Host.new("example.com", host_validation: :syntax)
18
+ assert_instance_of FalseClass, a.dns_enabled?
19
+ a = EmailAddress::Host.new("example.com", dns_lookup: :off)
21
20
  assert_instance_of FalseClass, a.dns_enabled?
22
- EmailAddress::Config.configure(host_validation: old_setting)
23
21
  end
24
22
 
25
23
  def test_foreign_host
@@ -53,54 +51,54 @@ class TestHost < MiniTest::Test
53
51
 
54
52
  def test_dmarc
55
53
  d = EmailAddress::Host.new("yahoo.com").dmarc
56
- assert_equal 'reject', d[:p]
54
+ assert_equal "reject", d[:p]
57
55
  d = EmailAddress::Host.new("example.com").dmarc
58
56
  assert_equal true, d.empty?
59
57
  end
60
58
 
61
59
  def test_ipv4
62
- h = EmailAddress::Host.new("[127.0.0.1]", host_allow_ip:true, host_local:true)
60
+ h = EmailAddress::Host.new("[127.0.0.1]", host_allow_ip: true, host_local: true)
63
61
  assert_equal "127.0.0.1", h.ip_address
64
62
  assert_equal true, h.valid?
65
63
  end
66
64
 
67
65
  def test_ipv6
68
- h = EmailAddress::Host.new("[IPv6:::1]", host_allow_ip:true, host_local:true)
66
+ h = EmailAddress::Host.new("[IPv6:::1]", host_allow_ip: true, host_local: true)
69
67
  assert_equal "::1", h.ip_address
70
68
  assert_equal true, h.valid?
71
69
  end
72
70
 
73
71
  def test_comment
74
72
  h = EmailAddress::Host.new("(oops)gmail.com")
75
- assert_equal 'gmail.com', h.to_s
76
- assert_equal 'oops', h.comment
73
+ assert_equal "gmail.com", h.to_s
74
+ assert_equal "oops", h.comment
77
75
  h = EmailAddress::Host.new("gmail.com(oops)")
78
- assert_equal 'gmail.com', h.to_s
79
- assert_equal 'oops', h.comment
76
+ assert_equal "gmail.com", h.to_s
77
+ assert_equal "oops", h.comment
80
78
  end
81
79
 
82
80
  def test_matches
83
81
  h = EmailAddress::Host.new("yahoo.co.jp")
84
82
  assert_equal false, h.matches?("gmail.com")
85
- assert_equal 'yahoo.co.jp', h.matches?("yahoo.co.jp")
86
- assert_equal '.co.jp', h.matches?(".co.jp")
87
- assert_equal '.jp', h.matches?(".jp")
88
- assert_equal 'yahoo.', h.matches?("yahoo.")
89
- assert_equal 'yah*.jp', h.matches?("yah*.jp")
83
+ assert_equal "yahoo.co.jp", h.matches?("yahoo.co.jp")
84
+ assert_equal ".co.jp", h.matches?(".co.jp")
85
+ assert_equal ".jp", h.matches?(".jp")
86
+ assert_equal "yahoo.", h.matches?("yahoo.")
87
+ assert_equal "yah*.jp", h.matches?("yah*.jp")
90
88
  end
91
89
 
92
90
  def test_ipv4_matches
93
- h = EmailAddress::Host.new("[123.123.123.8]", host_allow_ip:true)
91
+ h = EmailAddress::Host.new("[123.123.123.8]", host_allow_ip: true)
94
92
  assert_equal "123.123.123.8", h.ip_address
95
93
  assert_equal false, h.matches?("127.0.0.0/8")
96
- assert_equal '123.123.123.0/24', h.matches?("123.123.123.0/24")
94
+ assert_equal "123.123.123.0/24", h.matches?("123.123.123.0/24")
97
95
  end
98
96
 
99
97
  def test_ipv6_matches
100
- h = EmailAddress::Host.new("[IPV6:2001:db8::1]", host_allow_ip:true)
98
+ h = EmailAddress::Host.new("[IPV6:2001:db8::1]", host_allow_ip: true)
101
99
  assert_equal "2001:db8::1", h.ip_address
102
100
  assert_equal false, h.matches?("2002:db8::/118")
103
- assert_equal '2001:db8::/118', h.matches?("2001:db8::/118")
101
+ assert_equal "2001:db8::/118", h.matches?("2001:db8::/118")
104
102
  end
105
103
 
106
104
  def test_regexen
@@ -112,18 +110,18 @@ class TestHost < MiniTest::Test
112
110
  end
113
111
 
114
112
  def test_hosted_service
115
- assert EmailAddress.valid?('test@jiff.com', dns_lookup: :mx)
116
- assert ! EmailAddress.valid?('test@gmail.com', dns_lookup: :mx)
113
+ assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
114
+ assert !EmailAddress.valid?("test@gmail.com", dns_lookup: :mx)
117
115
  end
118
116
 
119
117
  def test_yahoo_bad_tld
120
- assert ! EmailAddress.valid?('test@yahoo.badtld')
121
- assert ! EmailAddress.valid?('test@yahoo.wtf') # Registered, but MX IP = 0.0.0.0
118
+ assert !EmailAddress.valid?("test@yahoo.badtld")
119
+ assert !EmailAddress.valid?("test@yahoo.wtf") # Registered, but MX IP = 0.0.0.0
122
120
  end
123
121
 
124
122
  def test_bad_formats
125
- assert ! EmailAddress::Host.new('ya hoo.com').valid?
126
- assert EmailAddress::Host.new('ya hoo.com', host_remove_spaces:true).valid?
123
+ assert !EmailAddress::Host.new("ya hoo.com").valid?
124
+ assert EmailAddress::Host.new("ya hoo.com", host_remove_spaces: true).valid?
127
125
  end
128
126
 
129
127
  def test_errors
@@ -133,7 +131,7 @@ class TestHost < MiniTest::Test
133
131
  assert_nil EmailAddress::Host.new("ajsdfhajshdfklasjhd.wtf", host_validation: :syntax).error
134
132
  assert_equal EmailAddress::Host.new("ya hoo.com", host_validation: :syntax).error, "Invalid Domain Name"
135
133
  assert_equal EmailAddress::Host.new("[127.0.0.1]").error, "IP Addresses are not allowed"
136
- assert_equal EmailAddress::Host.new("[127.0.0.666]", host_allow_ip:true).error, "This is not a valid IPv4 address"
137
- assert_equal EmailAddress::Host.new("[IPv6::12t]", host_allow_ip:true).error, "This is not a valid IPv6 address"
134
+ assert_equal EmailAddress::Host.new("[127.0.0.666]", host_allow_ip: true).error, "This is not a valid IPv4 address"
135
+ assert_equal EmailAddress::Host.new("[IPv6::12t]", host_allow_ip: true).error, "This is not a valid IPv6 address"
138
136
  end
139
137
  end
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+ require_relative 'test_helper'
3
+
4
+ class TestAliasing < MiniTest::Test
5
+ def setup
6
+ Object.send(:const_set, :EmailAddressValidator, EmailAddress)
7
+ Object.send(:remove_const, :EmailAddress)
8
+ end
9
+
10
+ def test_email_address_not_defined
11
+ assert_nil defined?(EmailAddress)
12
+ assert_nil defined?(EmailAddress::Address)
13
+ assert_nil defined?(EmailAddress::Config)
14
+ assert_nil defined?(EmailAddress::Exchanger)
15
+ assert_nil defined?(EmailAddress::Host)
16
+ assert_nil defined?(EmailAddress::Local)
17
+ assert_nil defined?(EmailAddress::Rewriter)
18
+ end
19
+
20
+ def test_alias_defined
21
+ assert_equal defined?(EmailAddressValidator), "constant"
22
+ assert_equal defined?(EmailAddressValidator::Address), "constant"
23
+ assert_equal defined?(EmailAddressValidator::Config), "constant"
24
+ assert_equal defined?(EmailAddressValidator::Exchanger), "constant"
25
+ assert_equal defined?(EmailAddressValidator::Host), "constant"
26
+ assert_equal defined?(EmailAddressValidator::Local), "constant"
27
+ assert_equal defined?(EmailAddressValidator::Rewriter), "constant"
28
+ end
29
+
30
+ def test_alias_class_methods
31
+ assert_equal true, EmailAddressValidator.valid?("user@yahoo.com")
32
+ end
33
+
34
+ def test_alias_host_methods
35
+ assert_equal true, EmailAddressValidator::Host.new("yahoo.com").valid?
36
+ end
37
+
38
+ def test_alias_address_methods
39
+ assert_equal true, EmailAddressValidator::Address.new("user@yahoo.com").valid?
40
+ end
41
+
42
+ def test_alias_config_methods
43
+ assert Hash, EmailAddressValidator::Config.new.to_h
44
+ end
45
+
46
+ def test_alias_local_methods
47
+ assert_equal true, EmailAddressValidator::Local.new("user").valid?
48
+ end
49
+
50
+ def teardown
51
+ Object.send(:const_set, :EmailAddress, EmailAddressValidator)
52
+ Object.send(:remove_const, :EmailAddressValidator)
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -162,13 +162,14 @@ files:
162
162
  - test/email_address/test_host.rb
163
163
  - test/email_address/test_local.rb
164
164
  - test/email_address/test_rewriter.rb
165
+ - test/test_aliasing.rb
165
166
  - test/test_email_address.rb
166
167
  - test/test_helper.rb
167
168
  homepage: https://github.com/afair/email_address
168
169
  licenses:
169
170
  - MIT
170
171
  metadata: {}
171
- post_install_message:
172
+ post_install_message:
172
173
  rdoc_options: []
173
174
  require_paths:
174
175
  - lib
@@ -183,8 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  - !ruby/object:Gem::Version
184
185
  version: '0'
185
186
  requirements: []
186
- rubygems_version: 3.1.2
187
- signing_key:
187
+ rubygems_version: 3.0.6
188
+ signing_key:
188
189
  specification_version: 4
189
190
  summary: This gem provides a ruby language library for working with and validating
190
191
  email addresses. By default, it validates against conventional usage, the format
@@ -199,5 +200,6 @@ test_files:
199
200
  - test/email_address/test_host.rb
200
201
  - test/email_address/test_local.rb
201
202
  - test/email_address/test_rewriter.rb
203
+ - test/test_aliasing.rb
202
204
  - test/test_email_address.rb
203
205
  - test/test_helper.rb