vjt-email_validator 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,9 +7,14 @@ class EmailValidator < ActiveModel::EachValidator
7
7
  local_part_special_chars = Regexp.escape('!#$%&\'*-/=?+-^_`{|}~')
8
8
  local_part_unquoted = '(?:[[:alnum:]' + local_part_special_chars + ']+[\.\+])*[[:alnum:]' + local_part_special_chars + '+]'
9
9
  local_part_quoted = '\"(?:[[:alnum:]' + local_part_special_chars + '\.]|\\\\[\x00-\xFF])*\"'
10
- domain_part = '@(?:(?:(?:\w+\-+[^_])|(?:\w+\.[a-z0-9-]*))*(?:[a-z0-9-]{1,63})\.[a-z]{2,6}(?:\.[a-z]{2,6})?'
11
- Pattern = Regexp.new('\A(?:' + local_part_unquoted + '+|' + local_part_quoted + '+)' + domain_part + '\Z)', Regexp::EXTENDED | Regexp::IGNORECASE, 'n').freeze
10
+ domain_part = '@(?:(?:(?:\w+\-+[^_])|(?:\w+\.[a-z0-9-]*))*(?:[a-z0-9-]{1,63})\.[a-z]{2,6}(?:\.[a-z]{2,6})?)'
11
+
12
+ email_address_regexp = '(?:' + local_part_unquoted + '+|' + local_part_quoted + '+)' + domain_part
13
+
14
+ Pattern = Regexp.new('\A' + email_address_regexp + '\Z', Regexp::EXTENDED | Regexp::IGNORECASE, 'n').freeze
15
+ Scanner = Regexp.new( email_address_regexp, Regexp::EXTENDED | Regexp::IGNORECASE, 'n').freeze
12
16
  Separator = /[;,\s]\s*/.freeze # for multiple e-mail addresses
17
+
13
18
  Defaults = {
14
19
  :message => I18n.t(:invalid_email_address, :scope => [:activerecord, :errors, :messages], :default => 'does not appear to be a valid e-mail address'),
15
20
  :multiple_message => I18n.t(:invalid_multiple_email, :scope => [:activerecord, :errors, :messages], :default => 'appears to contain an invalid e-mail address'),
@@ -49,6 +54,10 @@ class EmailValidator < ActiveModel::EachValidator
49
54
  end
50
55
 
51
56
  class << self
57
+ def extract(string)
58
+ string.scan(Scanner)
59
+ end
60
+
52
61
  def valid?(email, options = {})
53
62
  errors_on(email, options).nil?
54
63
  end
@@ -146,6 +146,17 @@ class EmailValidatorTest < TEST_CASE
146
146
  assert_equal false, EmailValidator.valid?('valid@example.com', :domain_length => 1)
147
147
  end
148
148
 
149
+ def test_scanning_of_addresses
150
+ assert_equal ['vjt@openssl.it', 'alex@dunae.ca'], EmailValidator.extract(%[
151
+ foo bar antani tapioca vjt@openssl.it
152
+ blatantly@wrong and.ano@ther-hey49039403.4930
153
+ alex@dunae.ca hey man can I haz chunky bacon?!
154
+ :-)
155
+ ])
156
+
157
+ assert_equal ['foo@example.org'], EmailValidator.extract('foo@example.org')
158
+ end
159
+
149
160
  protected
150
161
  def create_person(params)
151
162
  Person.new(params)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vjt-email_validator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 1
10
- version: 1.5.1
9
+ - 2
10
+ version: 1.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcello Barnaba
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-28 00:00:00 +01:00
19
+ date: 2011-03-03 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies: []
22
22