validate_url 1.0.2 → 1.0.13
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 +5 -5
- data/README.md +47 -13
- data/lib/locale/ar.yml +4 -0
- data/lib/locale/es.yml +4 -0
- data/lib/locale/fr.yml +4 -0
- data/lib/locale/ja.yml +1 -1
- data/lib/locale/km.yml +4 -0
- data/lib/locale/pl.yml +4 -0
- data/lib/locale/ro.yml +4 -0
- data/lib/locale/ru.yml +4 -0
- data/lib/locale/vi.yml +4 -0
- data/lib/locale/zh-CN.yml +4 -0
- data/lib/locale/zh-TW.yml +4 -0
- data/lib/validate_url/rspec_matcher.rb +12 -0
- data/lib/validate_url.rb +30 -14
- metadata +65 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 414a69dd5d0048f3563cafe2136e4b4c00731d4492afa77b4c9248bcd91f24d2
|
4
|
+
data.tar.gz: b92e07f5bdb42ff396395fd1adf40473ff08a4781397357cd752dbbbcb198523
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3bbe821276bf8f2c82e227a2b0c9bcb9aa76782994da820977a992e7bb0d9116a623d421e1850713cd8dfed91b22620c2d9bcd6d30770e1d198bf8486a13992
|
7
|
+
data.tar.gz: 07bf30ca4b67f8701baacd6505a3c9f64d792267cca3f672832b927e5f1df331ba32881faee2d755aa01abd92c7bbefde91795df3fd5da0246a8b82ed94fbd82
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Validates URL
|
2
2
|
|
3
|
-
This gem adds the capability of validating URLs to ActiveRecord and ActiveModel
|
3
|
+
This gem adds the capability of validating URLs to ActiveRecord and ActiveModel.
|
4
4
|
|
5
5
|
## Installation
|
6
|
-
|
7
|
-
```
|
6
|
+
|
7
|
+
```
|
8
8
|
# add this to your Gemfile
|
9
9
|
gem "validate_url"
|
10
10
|
|
11
|
-
#
|
11
|
+
# or run
|
12
12
|
sudo gem install validate_url
|
13
13
|
```
|
14
14
|
|
@@ -16,19 +16,25 @@ sudo gem install validate_url
|
|
16
16
|
|
17
17
|
### With ActiveRecord
|
18
18
|
|
19
|
-
```ruby
|
19
|
+
```ruby
|
20
20
|
class Pony < ActiveRecord::Base
|
21
21
|
# standard validation
|
22
|
-
validates :homepage, :
|
22
|
+
validates :homepage, url: true
|
23
23
|
|
24
24
|
# with allow_nil
|
25
|
-
validates :homepage, :
|
25
|
+
validates :homepage, url: { allow_nil: true }
|
26
26
|
|
27
27
|
# with allow_blank
|
28
|
-
validates :homepage, :
|
28
|
+
validates :homepage, url: { allow_blank: true }
|
29
29
|
|
30
30
|
# without local hostnames
|
31
|
-
validates :homepage, :
|
31
|
+
validates :homepage, url: { no_local: true }
|
32
|
+
|
33
|
+
# with custom schemes
|
34
|
+
validates :homepage, url: { schemes: ['https'] }
|
35
|
+
|
36
|
+
# with public suffix database https://publicsuffix.org/
|
37
|
+
validates :homepage, url: { public_suffix: true }
|
32
38
|
end
|
33
39
|
```
|
34
40
|
|
@@ -41,14 +47,30 @@ class Unicorn
|
|
41
47
|
attr_accessor :homepage
|
42
48
|
|
43
49
|
# with legacy syntax (the syntax above works also)
|
44
|
-
validates_url :homepage, :
|
50
|
+
validates_url :homepage, allow_blank: true
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### With RSpec
|
55
|
+
|
56
|
+
Require the matcher in `spec_helper.rb` or `rails_helper.rb`:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'validate_url/rspec_matcher'
|
60
|
+
```
|
61
|
+
|
62
|
+
In your spec:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
describe Unicorn
|
66
|
+
it { is_expected.to validate_url_of(:homepage) }
|
45
67
|
end
|
46
68
|
```
|
47
69
|
|
48
70
|
### I18n
|
49
71
|
|
50
|
-
The default error message `is not valid
|
51
|
-
You can pass the
|
72
|
+
The default error message `is not a valid URL`.
|
73
|
+
You can pass the `message: "my custom error"` option to your validation to define your own, custom message.
|
52
74
|
|
53
75
|
|
54
76
|
## Contributing
|
@@ -63,4 +85,16 @@ Validates URL is created and maintained by [PerfectLine](http://www.perfectline.
|
|
63
85
|
## License
|
64
86
|
|
65
87
|
Validates URL is Copyright © 2010-2014 [PerfectLine](http://www.perfectline.co), LLC. It is free software, and may be
|
66
|
-
redistributed under the terms specified in the LICENSE file.
|
88
|
+
redistributed under the terms specified in the LICENSE file.
|
89
|
+
|
90
|
+
## How to push new version
|
91
|
+
|
92
|
+
```
|
93
|
+
rake version:bump:patch
|
94
|
+
rake gemspec
|
95
|
+
```
|
96
|
+
Fix validate_url.gemspec to remove unneeded wrong strings
|
97
|
+
```
|
98
|
+
gem build validate_url.gemspec
|
99
|
+
gem push validate_url-1.0.8.gem
|
100
|
+
```
|
data/lib/locale/ar.yml
ADDED
data/lib/locale/es.yml
ADDED
data/lib/locale/fr.yml
ADDED
data/lib/locale/ja.yml
CHANGED
data/lib/locale/km.yml
ADDED
data/lib/locale/pl.yml
ADDED
data/lib/locale/ro.yml
ADDED
data/lib/locale/ru.yml
ADDED
data/lib/locale/vi.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
RSpec::Matchers.define :validate_url_of do |attribute|
|
2
|
+
match do
|
3
|
+
actual = subject.is_a?(Class) ? subject.new : subject
|
4
|
+
actual.send(:"#{attribute}=", "htp://invalidurl")
|
5
|
+
expect(actual).to be_invalid
|
6
|
+
@expected_message ||= I18n.t("errors.messages.url")
|
7
|
+
expect(actual.errors.messages[attribute.to_sym]).to include(@expected_message)
|
8
|
+
end
|
9
|
+
chain :with_message do |message|
|
10
|
+
@expected_message = message
|
11
|
+
end
|
12
|
+
end
|
data/lib/validate_url.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'addressable/uri'
|
2
1
|
require 'active_model'
|
3
2
|
require 'active_support/i18n'
|
4
|
-
|
5
|
-
I18n.load_path
|
6
|
-
I18n.load_path << File.dirname(__FILE__) + '/locale/ja.yml'
|
3
|
+
require 'public_suffix'
|
4
|
+
I18n.load_path += Dir[File.dirname(__FILE__) + "/locale/*.yml"]
|
7
5
|
|
8
6
|
module ActiveModel
|
9
7
|
module Validations
|
10
8
|
class UrlValidator < ActiveModel::EachValidator
|
9
|
+
RESERVED_OPTIONS = [:schemes, :no_local]
|
11
10
|
|
12
11
|
def initialize(options)
|
13
|
-
options.reverse_merge!(:
|
14
|
-
options.reverse_merge!(:
|
15
|
-
options.reverse_merge!(:
|
12
|
+
options.reverse_merge!(schemes: %w(http https))
|
13
|
+
options.reverse_merge!(message: :url)
|
14
|
+
options.reverse_merge!(no_local: false)
|
15
|
+
options.reverse_merge!(public_suffix: false)
|
16
16
|
|
17
17
|
super(options)
|
18
18
|
end
|
@@ -20,14 +20,30 @@ module ActiveModel
|
|
20
20
|
def validate_each(record, attribute, value)
|
21
21
|
schemes = [*options.fetch(:schemes)].map(&:to_s)
|
22
22
|
begin
|
23
|
-
uri =
|
24
|
-
|
25
|
-
|
23
|
+
uri = URI.parse(value)
|
24
|
+
host = uri && uri.host
|
25
|
+
scheme = uri && uri.scheme
|
26
|
+
|
27
|
+
valid_raw_url = scheme && value =~ /\A#{URI::regexp([scheme])}\z/
|
28
|
+
valid_scheme = host && scheme && schemes.include?(scheme)
|
29
|
+
valid_no_local = !options.fetch(:no_local) || (host && host.include?('.'))
|
30
|
+
valid_suffix = !options.fetch(:public_suffix) || (host && PublicSuffix.valid?(host, :default_rule => nil))
|
31
|
+
|
32
|
+
unless valid_raw_url && valid_scheme && valid_no_local && valid_suffix
|
33
|
+
record.errors.add(attribute, options.fetch(:message), value: value)
|
26
34
|
end
|
27
|
-
rescue
|
28
|
-
record.errors.add(attribute,
|
35
|
+
rescue URI::InvalidURIError
|
36
|
+
record.errors.add(attribute, :url, **filtered_options(value))
|
29
37
|
end
|
30
38
|
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def filtered_options(value)
|
43
|
+
filtered = options.except(*RESERVED_OPTIONS)
|
44
|
+
filtered[:value] = value
|
45
|
+
filtered
|
46
|
+
end
|
31
47
|
end
|
32
48
|
|
33
49
|
module ClassMethods
|
@@ -36,8 +52,8 @@ module ActiveModel
|
|
36
52
|
# class Unicorn
|
37
53
|
# include ActiveModel::Validations
|
38
54
|
# attr_accessor :homepage, :ftpsite
|
39
|
-
# validates_url :homepage, :
|
40
|
-
# validates_url :ftpsite, :
|
55
|
+
# validates_url :homepage, allow_blank: true
|
56
|
+
# validates_url :ftpsite, schemes: ['ftp']
|
41
57
|
# end
|
42
58
|
# Configuration options:
|
43
59
|
# * <tt>:message</tt> - A custom error message (default is: "is not a valid URL").
|
metadata
CHANGED
@@ -1,39 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate_url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanel Suurhans
|
8
8
|
- Tarmo Lehtpuu
|
9
9
|
- Vladimir Krylov
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: jeweler
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: '0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
30
|
+
name: sqlite3
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
|
-
type: :
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: activerecord
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
37
51
|
prerelease: false
|
38
52
|
version_requirements: !ruby/object:Gem::Requirement
|
39
53
|
requirements:
|
@@ -68,6 +82,34 @@ dependencies:
|
|
68
82
|
- - ">="
|
69
83
|
- !ruby/object:Gem::Version
|
70
84
|
version: 1.1.2
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: activemodel
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 3.0.0
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 3.0.0
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: public_suffix
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :runtime
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
71
113
|
description: Library for validating urls in Rails.
|
72
114
|
email:
|
73
115
|
- tanel.suurhans@perfectline.co
|
@@ -83,17 +125,28 @@ files:
|
|
83
125
|
- README.md
|
84
126
|
- init.rb
|
85
127
|
- install.rb
|
128
|
+
- lib/locale/ar.yml
|
86
129
|
- lib/locale/de.yml
|
87
130
|
- lib/locale/en.yml
|
131
|
+
- lib/locale/es.yml
|
132
|
+
- lib/locale/fr.yml
|
88
133
|
- lib/locale/it.yml
|
89
134
|
- lib/locale/ja.yml
|
135
|
+
- lib/locale/km.yml
|
136
|
+
- lib/locale/pl.yml
|
90
137
|
- lib/locale/pt-BR.yml
|
138
|
+
- lib/locale/ro.yml
|
139
|
+
- lib/locale/ru.yml
|
91
140
|
- lib/locale/tr.yml
|
141
|
+
- lib/locale/vi.yml
|
142
|
+
- lib/locale/zh-CN.yml
|
143
|
+
- lib/locale/zh-TW.yml
|
92
144
|
- lib/validate_url.rb
|
145
|
+
- lib/validate_url/rspec_matcher.rb
|
93
146
|
homepage: http://github.com/perfectline/validates_url/tree/master
|
94
147
|
licenses: []
|
95
148
|
metadata: {}
|
96
|
-
post_install_message:
|
149
|
+
post_install_message:
|
97
150
|
rdoc_options: []
|
98
151
|
require_paths:
|
99
152
|
- lib
|
@@ -108,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
161
|
- !ruby/object:Gem::Version
|
109
162
|
version: '0'
|
110
163
|
requirements: []
|
111
|
-
|
112
|
-
|
113
|
-
signing_key:
|
164
|
+
rubygems_version: 3.0.8
|
165
|
+
signing_key:
|
114
166
|
specification_version: 4
|
115
167
|
summary: Library for validating urls in Rails.
|
116
168
|
test_files: []
|