validators 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -244,7 +244,6 @@
244
244
  "chat",
245
245
  "cheap",
246
246
  "chintai",
247
- "chloe",
248
247
  "christmas",
249
248
  "chrome",
250
249
  "chrysler",
@@ -538,6 +537,7 @@
538
537
  "gratis",
539
538
  "green",
540
539
  "gripe",
540
+ "grocery",
541
541
  "group",
542
542
  "gs",
543
543
  "gt",
@@ -594,7 +594,6 @@
594
594
  "hr",
595
595
  "hsbc",
596
596
  "ht",
597
- "htc",
598
597
  "hu",
599
598
  "hughes",
600
599
  "hyatt",
@@ -745,6 +744,7 @@
745
744
  "living",
746
745
  "lixil",
747
746
  "lk",
747
+ "llc",
748
748
  "loan",
749
749
  "loans",
750
750
  "locker",
@@ -778,6 +778,7 @@
778
778
  "man",
779
779
  "management",
780
780
  "mango",
781
+ "map",
781
782
  "market",
782
783
  "marketing",
783
784
  "markets",
@@ -787,8 +788,6 @@
787
788
  "mattel",
788
789
  "mba",
789
790
  "mc",
790
- "mcd",
791
- "mcdonalds",
792
791
  "mckinsey",
793
792
  "md",
794
793
  "me",
@@ -801,6 +800,7 @@
801
800
  "men",
802
801
  "menu",
803
802
  "meo",
803
+ "merckmsd",
804
804
  "metlife",
805
805
  "mg",
806
806
  "mh",
@@ -829,7 +829,6 @@
829
829
  "monash",
830
830
  "money",
831
831
  "monster",
832
- "montblanc",
833
832
  "mopar",
834
833
  "mormon",
835
834
  "mortgage",
@@ -935,7 +934,6 @@
935
934
  "ovh",
936
935
  "pa",
937
936
  "page",
938
- "pamperedchef",
939
937
  "panasonic",
940
938
  "panerai",
941
939
  "paris",
@@ -953,6 +951,7 @@
953
951
  "pg",
954
952
  "ph",
955
953
  "pharmacy",
954
+ "phd",
956
955
  "philips",
957
956
  "phone",
958
957
  "photo",
@@ -1098,6 +1097,7 @@
1098
1097
  "scot",
1099
1098
  "sd",
1100
1099
  "se",
1100
+ "search",
1101
1101
  "seat",
1102
1102
  "secure",
1103
1103
  "security",
@@ -1157,6 +1157,7 @@
1157
1157
  "soy",
1158
1158
  "space",
1159
1159
  "spiegel",
1160
+ "sport",
1160
1161
  "spot",
1161
1162
  "spreadbetting",
1162
1163
  "sr",
@@ -1369,13 +1370,16 @@
1369
1370
  "xn--11b4c3d",
1370
1371
  "xn--1ck2e1b",
1371
1372
  "xn--1qqw23a",
1373
+ "xn--2scrj9c",
1372
1374
  "xn--30rr7y",
1373
1375
  "xn--3bst00m",
1374
1376
  "xn--3ds443g",
1375
1377
  "xn--3e0b707e",
1378
+ "xn--3hcrj9c",
1376
1379
  "xn--3oq18vl8pn36a",
1377
1380
  "xn--3pxu8k",
1378
1381
  "xn--42c2d9a",
1382
+ "xn--45br5cyl",
1379
1383
  "xn--45brj9c",
1380
1384
  "xn--45q11c",
1381
1385
  "xn--4gbrim",
@@ -1429,7 +1433,9 @@
1429
1433
  "xn--gckr3f0f",
1430
1434
  "xn--gecrj9c",
1431
1435
  "xn--gk3at1e",
1436
+ "xn--h2breg3eve",
1432
1437
  "xn--h2brj9c",
1438
+ "xn--h2brj9c8c",
1433
1439
  "xn--hxt814e",
1434
1440
  "xn--i1b6b1a6a2e",
1435
1441
  "xn--imr513n",
@@ -1456,10 +1462,12 @@
1456
1462
  "xn--mgbai9azgqp6j",
1457
1463
  "xn--mgbayh7gpa",
1458
1464
  "xn--mgbb9fbpob",
1465
+ "xn--mgbbh1a",
1459
1466
  "xn--mgbbh1a71e",
1460
1467
  "xn--mgbc0a9azcg",
1461
1468
  "xn--mgbca7dzdo",
1462
1469
  "xn--mgberp4a5d4ar",
1470
+ "xn--mgbgu82a",
1463
1471
  "xn--mgbi4ecexp",
1464
1472
  "xn--mgbpl2fh",
1465
1473
  "xn--mgbt3dhd",
@@ -1477,6 +1485,7 @@
1477
1485
  "xn--nyqy26a",
1478
1486
  "xn--o3cw4h",
1479
1487
  "xn--ogbpf8fl",
1488
+ "xn--otu796d",
1480
1489
  "xn--p1acf",
1481
1490
  "xn--p1ai",
1482
1491
  "xn--pbt977c",
@@ -1487,6 +1496,7 @@
1487
1496
  "xn--qxam",
1488
1497
  "xn--rhqv96g",
1489
1498
  "xn--rovu88b",
1499
+ "xn--rvc1e0am3e",
1490
1500
  "xn--s9brj9c",
1491
1501
  "xn--ses554g",
1492
1502
  "xn--t60b56a",
@@ -4,6 +4,7 @@ module Validators
4
4
  require "validators/constants"
5
5
  require "validators/ip"
6
6
  require "validators/tld"
7
+ require "validators/hostname"
7
8
  require "validators/disposable_hostnames"
8
9
  require "validators/validates_datetime"
9
10
  require "validators/validates_ip_address"
@@ -15,5 +16,4 @@ module Validators
15
16
  require "validators/validates_ssh_private_key"
16
17
  require "validators/validates_ssh_public_key"
17
18
  require "validators/validates_hostname_format_of"
18
- require "validators/validates_subdomain_format_of"
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module Validators
2
- EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,4}\z/i
2
+ EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,}\z/i
3
3
 
4
4
  # Source: https://github.com/henrik/validates_url_format_of
5
5
  IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
@@ -0,0 +1,26 @@
1
+ module Validators
2
+ class Hostname
3
+ def self.valid?(host)
4
+ host = host.to_s
5
+ uri = URI(host)
6
+
7
+ host.present? &&
8
+ uri.host.nil? &&
9
+ uri.scheme.nil? &&
10
+ uri.fragment.nil? &&
11
+ uri.query.nil? &&
12
+ uri.path == host &&
13
+ host.split(".").all? {|label| valid_label?(label) } &&
14
+ host.size <= 255 &&
15
+ Validators::TLD.host_with_valid_tld?(host)
16
+ rescue URI::InvalidURIError
17
+ false
18
+ end
19
+
20
+ def self.valid_label?(label)
21
+ !label.start_with?('-') &&
22
+ !label.match(/\A\d+\z/) &&
23
+ label.match(/\A[a-z0-9-]{1,63}\z/i)
24
+ end
25
+ end
26
+ end
@@ -7,7 +7,7 @@ module Validators
7
7
  end
8
8
 
9
9
  def self.host_with_valid_tld?(host)
10
- return false if host.split('.').size == 1
10
+ return false if host.split(".").size == 1
11
11
  valid? host[/\.([^.]+)$/, 1].to_s.downcase
12
12
  end
13
13
 
@@ -3,10 +3,12 @@ module ActiveModel
3
3
  class EmailValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
5
  allow_disposable = options.fetch(:disposable, false)
6
+ check_tld = options.fetch(:tld, false)
6
7
 
7
8
  return if value.blank? && options[:allow_blank]
8
9
  return if value.nil? && options[:allow_nil]
9
10
 
11
+ validate_tld(record, attribute, value, options) if check_tld
10
12
  validate_email_format(record, attribute, value, options)
11
13
  validate_disposable_email(record, attribute, value, options) unless allow_disposable
12
14
  end
@@ -14,12 +16,26 @@ module ActiveModel
14
16
  def validate_email_format(record, attribute, value, options)
15
17
  if value.to_s !~ Validators::EMAIL_FORMAT
16
18
  record.errors.add(
17
- attribute, :invalid_email,
18
- :message => options[:message], :value => value
19
+ attribute,
20
+ :invalid_email,
21
+ message: options[:message],
22
+ value: value
19
23
  )
20
24
  end
21
25
  end
22
26
 
27
+ def validate_tld(record, attribute, value, options)
28
+ host = value.to_s.split("@").last
29
+ return if Validators::TLD.host_with_valid_tld?(host)
30
+
31
+ record.errors.add(
32
+ attribute,
33
+ :invalid_hostname,
34
+ message: options[:message],
35
+ value: value
36
+ )
37
+ end
38
+
23
39
  def validate_disposable_email(record, attribute, value, options)
24
40
  hostname = value.to_s.split("@").last.to_s.downcase
25
41
 
@@ -5,41 +5,15 @@ module ActiveModel
5
5
  def validate_each(record, attribute, value)
6
6
  return if value.blank? && options[:allow_blank]
7
7
  return if value.nil? && options[:allow_nil]
8
- return if valid_hostname?(value.to_s)
8
+ return if Validators::Hostname.valid?(value.to_s)
9
9
 
10
- record.errors.add(attribute, :invalid_hostname,
11
- :message => options[:message],
12
- :value => value
10
+ record.errors.add(
11
+ attribute,
12
+ :invalid_hostname,
13
+ message: options[:message],
14
+ value: value
13
15
  )
14
16
  end
15
-
16
- def valid_hostname?(host)
17
- host = host.to_s
18
- uri = URI(host)
19
-
20
- host.present? &&
21
- uri.host.nil? &&
22
- uri.scheme.nil? &&
23
- uri.fragment.nil? &&
24
- uri.query.nil? &&
25
- uri.path == host &&
26
- host.split('.').all? {|label| valid_label?(label) } &&
27
- host.size <= 255 &&
28
- valid_tld?(host)
29
- rescue URI::InvalidURIError
30
- false
31
- end
32
-
33
- def valid_label?(label)
34
- !label.start_with?('-') &&
35
- !label.match(/\A\d+\z/) &&
36
- label.match(/\A[a-z0-9-]{1,63}\z/i)
37
- end
38
-
39
- def valid_tld?(host)
40
- return true unless options[:tld]
41
- Validators::TLD.host_with_valid_tld?(host)
42
- end
43
17
  end
44
18
 
45
19
  module ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Validators
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 6
4
+ MINOR = 7
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
@@ -21,8 +21,7 @@ INVALID_EMAILS = [
21
21
  # corrected in http://www.rfc-editor.org/errata_search.php?rfc=3696
22
22
  'Fred\ Bloggs_@example.com',
23
23
  'Abc\@def+@example.com',
24
- 'Joe.\\Blow@example.com',
25
- "invalid@invalid.invalid"
24
+ 'Joe.\\Blow@example.com'
26
25
  ]
27
26
 
28
27
  VALID_EMAILS = [
@@ -58,13 +58,13 @@ class ServerWithTLD
58
58
  end
59
59
  end
60
60
 
61
- class Site
61
+ class EmailWithTLD
62
62
  include ActiveModel::Validations
63
- attr_accessor :slug
63
+ attr_accessor :email
64
64
 
65
- validates_subdomain :slug
65
+ validates_email :email, tld: true
66
66
 
67
- def initialize(slug)
68
- @slug = slug
67
+ def initialize(email)
68
+ @email = email
69
69
  end
70
70
  end
@@ -15,6 +15,7 @@ en:
15
15
  invalid_cpf: "is not a valid CPF"
16
16
  invalid_cnpj: "is not a valid CNPJ"
17
17
  disposable_email: "is not allowed (high-bounce domain)"
18
+ invalid_hostname: "does not have a valid hostname"
18
19
 
19
20
  activemodel:
20
21
  <<: *activerecord
@@ -2,9 +2,9 @@ require "test_helper"
2
2
 
3
3
  class ValidatesEmailFormatOfTest < Minitest::Test
4
4
  setup do
5
- User.validates_email_format_of :email, :corporate_email, :allow_blank => false
6
- Buyer.validates_email_format_of :email, :message => "is not a valid e-mail"
7
- Person.validates :email, :email => true
5
+ User.validates_email_format_of :email, :corporate_email, allow_blank: false
6
+ Buyer.validates_email_format_of :email, message: "is not a valid e-mail"
7
+ Person.validates :email, email: true
8
8
  end
9
9
 
10
10
  VALID_EMAILS.each do |email|
@@ -19,10 +19,10 @@ class ValidatesEmailFormatOfTest < Minitest::Test
19
19
 
20
20
  INVALID_EMAILS.each do |email|
21
21
  test "rejects #{email.inspect} as a valid email" do
22
- user = User.new(:email => "invalid", :corporate_email => "invalid")
22
+ user = User.new(:email => email, :corporate_email => "invalid")
23
23
  refute user.valid?
24
24
 
25
- user = Person.new(:email => "invalid")
25
+ user = Person.new(:email => email)
26
26
  refute user.valid?
27
27
  end
28
28
  end
@@ -73,4 +73,11 @@ class ValidatesEmailFormatOfTest < Minitest::Test
73
73
  test "defines alias method" do
74
74
  assert User.respond_to?(:validates_email)
75
75
  end
76
+
77
+ test "rejects invalid tld" do
78
+ user = EmailWithTLD.new(email: "john@example.zaz")
79
+
80
+ refute user.valid?
81
+ assert_includes user.errors[:email], "does not have a valid hostname"
82
+ end
76
83
  end
@@ -17,12 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_development_dependency "activerecord", ">= 3.0"
20
+ s.add_development_dependency "activerecord"
21
21
  s.add_development_dependency "minitest-utils"
22
22
  s.add_development_dependency "sqlite3-ruby"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_development_dependency "pry-meta"
25
25
  s.add_development_dependency "cpf_cnpj"
26
26
  s.add_development_dependency "sshkey"
27
- s.add_development_dependency "codeclimate-test-reporter"
27
+ s.add_development_dependency "simplecov"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest-utils
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: codeclimate-test-reporter
112
+ name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -143,6 +143,7 @@ files:
143
143
  - lib/validators.rb
144
144
  - lib/validators/constants.rb
145
145
  - lib/validators/disposable_hostnames.rb
146
+ - lib/validators/hostname.rb
146
147
  - lib/validators/ip.rb
147
148
  - lib/validators/tld.rb
148
149
  - lib/validators/validates_cnpj_format_of.rb
@@ -154,7 +155,6 @@ files:
154
155
  - lib/validators/validates_ownership_of.rb
155
156
  - lib/validators/validates_ssh_private_key.rb
156
157
  - lib/validators/validates_ssh_public_key.rb
157
- - lib/validators/validates_subdomain_format_of.rb
158
158
  - lib/validators/validates_url_format_of.rb
159
159
  - lib/validators/version.rb
160
160
  - test/schema.rb
@@ -163,7 +163,6 @@ files:
163
163
  - test/support/hostnames.rb
164
164
  - test/support/ips.rb
165
165
  - test/support/models.rb
166
- - test/support/subdomains.rb
167
166
  - test/support/translations.yml
168
167
  - test/support/urls.rb
169
168
  - test/test_helper.rb
@@ -186,7 +185,6 @@ files:
186
185
  - test/validators/validates_ssh_private_key/dsa_test.rb
187
186
  - test/validators/validates_ssh_private_key/rsa_test.rb
188
187
  - test/validators/validates_ssh_public_key_test.rb
189
- - test/validators/validates_subdomain_test.rb
190
188
  - test/validators/validates_url_format_of/with_tld_validation_test.rb
191
189
  - test/validators/validates_url_format_of/without_tld_validation_test.rb
192
190
  - validators.gemspec
@@ -210,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
208
  version: '0'
211
209
  requirements: []
212
210
  rubyforge_project:
213
- rubygems_version: 2.6.11
211
+ rubygems_version: 2.7.3
214
212
  signing_key:
215
213
  specification_version: 4
216
214
  summary: Add some nice ActiveModel/ActiveRecord validators.
@@ -221,7 +219,6 @@ test_files:
221
219
  - test/support/hostnames.rb
222
220
  - test/support/ips.rb
223
221
  - test/support/models.rb
224
- - test/support/subdomains.rb
225
222
  - test/support/translations.yml
226
223
  - test/support/urls.rb
227
224
  - test/test_helper.rb
@@ -244,6 +241,5 @@ test_files:
244
241
  - test/validators/validates_ssh_private_key/dsa_test.rb
245
242
  - test/validators/validates_ssh_private_key/rsa_test.rb
246
243
  - test/validators/validates_ssh_public_key_test.rb
247
- - test/validators/validates_subdomain_test.rb
248
244
  - test/validators/validates_url_format_of/with_tld_validation_test.rb
249
245
  - test/validators/validates_url_format_of/without_tld_validation_test.rb