href_sanitizer 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b32b934a9123ac89d9c9565b206bbb3aaa74ab8556188fc98011114c0c599f74
4
- data.tar.gz: b1c2cedb3d0206e284c9a13ed98d64630f399edd27e4ba0d230ecefad72cf3a8
3
+ metadata.gz: 00de4b6bbe17f7fc742280bc420a6459d48db06c3256f84e9738b7bc30862017
4
+ data.tar.gz: c118fdfd859730fe4c440a493764ff3e96d8d155cad88697bee34c8f23579d98
5
5
  SHA512:
6
- metadata.gz: 3e5937d4b43e8d37af0a08082ebd2c0d3a096560f971e43c37f38a81003c4e19601ae7f578023ae355683ddcbbfc26c619617237e1a49d28a9d2f8160be63725
7
- data.tar.gz: c0dbe7a6a7fe7af039ed8326aafe3f40aafe27361e2bee3d5f2d2e7e2aae89852ac0a39a998554606dbbeecf501c0dbde75e12bfd43a4736be5ba1cfb0a3c5c7
6
+ metadata.gz: d241938c9c7837db70d70eb0fcf08f88451ec16062f30d429ca033c2cd2935180acdc1fc6cdd5dad653650436ecbc70a167812c3f1e196558956489f0c4ad8e4
7
+ data.tar.gz: 40ad36cc158724566bb0a31a68962f61f59547516d151d1eecd034f9dd80d53c53bf86c498c0c24ca459c82106203c1e8a97e2f1905b02edb6a92462e599facd
@@ -17,50 +17,49 @@ require "href_sanitizer/url_sanitizer"
17
17
  # Class name is UrlValidator, but we also alias as URLValidator
18
18
  # to support apps with `inflect.acronym 'URL'` (which makes Rails
19
19
  # resolve `validates :field, url: true` to URLValidator).
20
- class UrlValidator < ActiveModel::EachValidator
21
- EMAIL_REGEXP = /\A[^@\s]+@[^@\s]+\z/
20
+ module HrefSanitizer
21
+ class UrlValidator < ActiveModel::EachValidator
22
+ EMAIL_REGEXP = /\A[^@\s]+@[^@\s]+\z/
22
23
 
23
- def validate_each(record, attribute, value)
24
- stripped = value.to_s.strip
24
+ def validate_each(record, attribute, value)
25
+ stripped = value.to_s.strip
25
26
 
26
- # Accept bare email addresses when accept_email: true
27
- if options.fetch(:accept_email, false) && stripped.match?(EMAIL_REGEXP)
28
- return
29
- end
27
+ # Accept bare email addresses when accept_email: true
28
+ if options.fetch(:accept_email, false) && stripped.match?(EMAIL_REGEXP)
29
+ return
30
+ end
30
31
 
31
- uri = parse(stripped)
32
- unless uri
33
- record.errors.add(attribute, options.fetch(:message, :url))
34
- return
35
- end
32
+ uri = parse(stripped)
33
+ unless uri
34
+ record.errors.add(attribute, options.fetch(:message, :url))
35
+ return
36
+ end
36
37
 
37
- allowed_schemes = options.fetch(:schemes, %w[http https])
38
- unless uri.scheme&.downcase&.in?(allowed_schemes)
39
- record.errors.add(attribute, options.fetch(:message, :url))
40
- return
41
- end
38
+ allowed_schemes = options.fetch(:schemes, %w[http https])
39
+ unless uri.scheme&.downcase&.in?(allowed_schemes)
40
+ record.errors.add(attribute, options.fetch(:message, :url))
41
+ return
42
+ end
42
43
 
43
- unless HrefSanitizer::UrlSanitizer.allowed_uri?(stripped)
44
- record.errors.add(attribute, options.fetch(:message, :url))
45
- return
46
- end
44
+ unless HrefSanitizer::UrlSanitizer.allowed_uri?(stripped)
45
+ record.errors.add(attribute, options.fetch(:message, :url))
46
+ return
47
+ end
47
48
 
48
- if options.fetch(:no_local, false)
49
- unless HrefSanitizer::UrlSanitizer.public_url?(stripped)
50
- record.errors.add(attribute, options.fetch(:message, :private_ip_url))
49
+ if options.fetch(:no_local, false)
50
+ unless HrefSanitizer::UrlSanitizer.public_url?(stripped)
51
+ record.errors.add(attribute, options.fetch(:message, :private_ip_url))
52
+ end
51
53
  end
52
54
  end
53
- end
54
55
 
55
- private
56
+ private
56
57
 
57
- def parse(value)
58
- uri = Addressable::URI.parse(value)
59
- uri if uri.host.present?
60
- rescue Addressable::URI::InvalidURIError
61
- nil
58
+ def parse(value)
59
+ uri = Addressable::URI.parse(value)
60
+ uri if uri.host.present?
61
+ rescue Addressable::URI::InvalidURIError
62
+ nil
63
+ end
62
64
  end
63
65
  end
64
-
65
- # Alias for apps using `inflect.acronym 'URL'`
66
- URLValidator = UrlValidator
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HrefSanitizer
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -3,7 +3,6 @@
3
3
  require "href_sanitizer/version"
4
4
  require "href_sanitizer/url_sanitizer"
5
5
  require "href_sanitizer/url_validator"
6
- require "href_sanitizer/safe_url_validator"
7
6
  require "href_sanitizer/railtie" if defined?(Rails::Railtie)
8
7
 
9
8
  module HrefSanitizer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: href_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mfo
@@ -63,7 +63,6 @@ files:
63
63
  - lib/href_sanitizer.rb
64
64
  - lib/href_sanitizer/link_to_patch.rb
65
65
  - lib/href_sanitizer/railtie.rb
66
- - lib/href_sanitizer/safe_url_validator.rb
67
66
  - lib/href_sanitizer/url_sanitizer.rb
68
67
  - lib/href_sanitizer/url_validator.rb
69
68
  - lib/href_sanitizer/version.rb
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Backwards compatibility — safe_url: is an alias for url:
4
- require "href_sanitizer/url_validator"
5
- SafeUrlValidator = UrlValidator