validate_url 1.0.11 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -8
- data/lib/locale/ar.yml +4 -0
- data/lib/locale/es.yml +4 -0
- data/lib/locale/it.yml +1 -1
- data/lib/locale/nl.yml +4 -0
- data/lib/locale/pl.yml +1 -1
- data/lib/locale/pt-PT.yml +4 -0
- data/lib/locale/pt.yml +4 -0
- data/lib/locale/vi.yml +4 -0
- data/lib/validate_url.rb +34 -13
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b59a8faf6055485804d8dbc80aa6f70cec016dabf65eb0fa79d0cb9d3c6db5
|
4
|
+
data.tar.gz: b9015820dc18729bab6cbe3e67d982918e7727ad611d7ab916e854dbf39b7a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a630fa8358388a40491e00d3275fa543076a8d4c00df65d18a1e5d70426e862245b5631125782c72eab76cdbbdcff18f857f5a047e04cb8ec7bac36ccb770983
|
7
|
+
data.tar.gz: '09bd75d874a0087033f3984646b44466ffd275c58b77128dac06b4f8a1fe8bd13ab277a9e1317769a34407174f524380313b462b75f95f9be6a35340f15bf753'
|
data/README.md
CHANGED
@@ -4,11 +4,15 @@ This gem adds the capability of validating URLs to ActiveRecord and ActiveModel.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Add this to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
9
10
|
gem "validate_url"
|
11
|
+
```
|
12
|
+
|
13
|
+
Or install it yourself:
|
10
14
|
|
11
|
-
|
15
|
+
```sh
|
12
16
|
sudo gem install validate_url
|
13
17
|
```
|
14
18
|
|
@@ -35,6 +39,9 @@ class Pony < ActiveRecord::Base
|
|
35
39
|
|
36
40
|
# with public suffix database https://publicsuffix.org/
|
37
41
|
validates :homepage, url: { public_suffix: true }
|
42
|
+
|
43
|
+
# with Postgres array of urls, described [here](https://guides.rubyonrails.org/active_record_postgresql.html#array)
|
44
|
+
validates :homepage, url: { accept_array: true }
|
38
45
|
end
|
39
46
|
```
|
40
47
|
|
@@ -62,7 +69,7 @@ require 'validate_url/rspec_matcher'
|
|
62
69
|
In your spec:
|
63
70
|
|
64
71
|
```ruby
|
65
|
-
describe Unicorn
|
72
|
+
RSpec.describe Unicorn
|
66
73
|
it { is_expected.to validate_url_of(:homepage) }
|
67
74
|
end
|
68
75
|
```
|
@@ -87,14 +94,16 @@ Validates URL is created and maintained by [PerfectLine](http://www.perfectline.
|
|
87
94
|
Validates URL is Copyright © 2010-2014 [PerfectLine](http://www.perfectline.co), LLC. It is free software, and may be
|
88
95
|
redistributed under the terms specified in the LICENSE file.
|
89
96
|
|
90
|
-
## How to push new version
|
97
|
+
## How to push a new version
|
91
98
|
|
92
|
-
```
|
99
|
+
```sh
|
93
100
|
rake version:bump:patch
|
94
101
|
rake gemspec
|
95
102
|
```
|
96
|
-
|
97
|
-
|
103
|
+
|
104
|
+
Manually update `validate_url.gemspec` to remove incorrect strings.
|
105
|
+
|
106
|
+
```sh
|
98
107
|
gem build validate_url.gemspec
|
99
108
|
gem push validate_url-1.0.8.gem
|
100
109
|
```
|
data/lib/locale/ar.yml
ADDED
data/lib/locale/es.yml
ADDED
data/lib/locale/it.yml
CHANGED
data/lib/locale/nl.yml
ADDED
data/lib/locale/pl.yml
CHANGED
data/lib/locale/pt.yml
ADDED
data/lib/locale/vi.yml
ADDED
data/lib/validate_url.rb
CHANGED
@@ -13,28 +13,32 @@ module ActiveModel
|
|
13
13
|
options.reverse_merge!(message: :url)
|
14
14
|
options.reverse_merge!(no_local: false)
|
15
15
|
options.reverse_merge!(public_suffix: false)
|
16
|
+
options.reverse_merge!(accept_array: false)
|
16
17
|
|
17
18
|
super(options)
|
18
19
|
end
|
19
20
|
|
20
21
|
def validate_each(record, attribute, value)
|
21
22
|
schemes = [*options.fetch(:schemes)].map(&:to_s)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
if value.respond_to?(:each)
|
24
|
+
# Error out if we're not allowing arrays
|
25
|
+
if !options.include?(:accept_array) || !options.fetch(:accept_array)
|
26
|
+
record.errors.add(attribute, :url, **filtered_options(value))
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# We have to manually handle `:allow_nil` and `:allow_blank` since it's not caught by
|
30
|
+
# ActiveRecord's own validators. We do that by just removing all the nil's if we want to
|
31
|
+
# allow them so it's not passed on later.
|
32
|
+
value = value.reject(&:nil?) if options.include?(:allow_nil) && options.fetch(:allow_nil)
|
33
|
+
value = value.reject(&:blank?) if options.include?(:allow_blank) && options.fetch(:allow_blank)
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
record.errors.add(attribute, :url, filtered_options(value))
|
35
|
+
result = value.flat_map { |v| validate_url(record, attribute, v, schemes) }
|
36
|
+
errors = result.reject(&:nil?)
|
37
|
+
|
38
|
+
return errors.any? ? errors.first : true
|
37
39
|
end
|
40
|
+
|
41
|
+
validate_url(record, attribute, value, schemes)
|
38
42
|
end
|
39
43
|
|
40
44
|
protected
|
@@ -44,6 +48,23 @@ module ActiveModel
|
|
44
48
|
filtered[:value] = value
|
45
49
|
filtered
|
46
50
|
end
|
51
|
+
|
52
|
+
def validate_url(record, attribute, value, schemes)
|
53
|
+
uri = URI.parse(value)
|
54
|
+
host = uri && uri.host
|
55
|
+
scheme = uri && uri.scheme
|
56
|
+
|
57
|
+
valid_raw_url = scheme && value =~ /\A#{URI::regexp([scheme])}\z/
|
58
|
+
valid_scheme = host && scheme && schemes.include?(scheme)
|
59
|
+
valid_no_local = !options.fetch(:no_local) || (host && host.include?('.'))
|
60
|
+
valid_suffix = !options.fetch(:public_suffix) || (host && PublicSuffix.valid?(host, :default_rule => nil))
|
61
|
+
|
62
|
+
unless valid_raw_url && valid_scheme && valid_no_local && valid_suffix
|
63
|
+
record.errors.add(attribute, options.fetch(:message), value: value)
|
64
|
+
end
|
65
|
+
rescue URI::InvalidURIError, URI::InvalidComponentError
|
66
|
+
record.errors.add(attribute, :url, **filtered_options(value))
|
67
|
+
end
|
47
68
|
end
|
48
69
|
|
49
70
|
module ClassMethods
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
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.15
|
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: 2022-05-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jeweler
|
@@ -125,17 +125,23 @@ files:
|
|
125
125
|
- README.md
|
126
126
|
- init.rb
|
127
127
|
- install.rb
|
128
|
+
- lib/locale/ar.yml
|
128
129
|
- lib/locale/de.yml
|
129
130
|
- lib/locale/en.yml
|
131
|
+
- lib/locale/es.yml
|
130
132
|
- lib/locale/fr.yml
|
131
133
|
- lib/locale/it.yml
|
132
134
|
- lib/locale/ja.yml
|
133
135
|
- lib/locale/km.yml
|
136
|
+
- lib/locale/nl.yml
|
134
137
|
- lib/locale/pl.yml
|
135
138
|
- lib/locale/pt-BR.yml
|
139
|
+
- lib/locale/pt-PT.yml
|
140
|
+
- lib/locale/pt.yml
|
136
141
|
- lib/locale/ro.yml
|
137
142
|
- lib/locale/ru.yml
|
138
143
|
- lib/locale/tr.yml
|
144
|
+
- lib/locale/vi.yml
|
139
145
|
- lib/locale/zh-CN.yml
|
140
146
|
- lib/locale/zh-TW.yml
|
141
147
|
- lib/validate_url.rb
|
@@ -143,7 +149,7 @@ files:
|
|
143
149
|
homepage: http://github.com/perfectline/validates_url/tree/master
|
144
150
|
licenses: []
|
145
151
|
metadata: {}
|
146
|
-
post_install_message:
|
152
|
+
post_install_message:
|
147
153
|
rdoc_options: []
|
148
154
|
require_paths:
|
149
155
|
- lib
|
@@ -158,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
164
|
- !ruby/object:Gem::Version
|
159
165
|
version: '0'
|
160
166
|
requirements: []
|
161
|
-
rubygems_version: 3.0.
|
162
|
-
signing_key:
|
167
|
+
rubygems_version: 3.0.8
|
168
|
+
signing_key:
|
163
169
|
specification_version: 4
|
164
170
|
summary: Library for validating urls in Rails.
|
165
171
|
test_files: []
|