opt_parse_validator 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +3 -0
- data/lib/opt_parse_validator/opts/uri.rb +11 -3
- data/lib/opt_parse_validator/version.rb +1 -1
- data/spec/lib/opt_parse_validator/opts/uri_spec.rb +18 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2723f3613fc6738288980bec82ff2541520ff7d
|
4
|
+
data.tar.gz: 0917da11c83e5ed23ee707b8c0858c367e5caac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0629015ce8aec7f45c5a30e96d4c9ebe2188fffd14c5813f800fa7786cdb694c7480958e6c97bd6826d869348f8364e25b92addcebd82ddb1ace3d3930116c2e
|
7
|
+
data.tar.gz: a36713b133c62e53dcdcc7cdf34188850be49c6fd9dc1f6122597e05fab572d92d85b3e6df0369667ea33afef6a7983f7fc9bc49858e1fd615a496d138ef3500
|
data/README.md
CHANGED
@@ -5,14 +5,22 @@ module OptParseValidator
|
|
5
5
|
@allowed_protocols ||= [*attrs[:protocols]]
|
6
6
|
end
|
7
7
|
|
8
|
+
# The default protocol (or scheme) to use if none was given
|
9
|
+
def default_protocol
|
10
|
+
@default_protocol ||= attrs[:default_protocol]
|
11
|
+
end
|
12
|
+
|
8
13
|
# @param [ String ] value
|
9
14
|
#
|
10
15
|
# @return [ String ]
|
11
16
|
def validate(value)
|
12
|
-
uri
|
13
|
-
|
17
|
+
uri = Addressable::URI.parse(value)
|
18
|
+
|
19
|
+
if !uri.scheme && default_protocol
|
20
|
+
uri = Addressable::URI.parse("#{default_protocol}://#{value}")
|
21
|
+
end
|
14
22
|
|
15
|
-
unless
|
23
|
+
unless allowed_protocols.empty? || allowed_protocols.include?(uri.scheme)
|
16
24
|
# For future refs: will have to check if the uri.scheme exists,
|
17
25
|
# otherwise it means that the value was empty
|
18
26
|
fail Addressable::URI::InvalidURIError
|
@@ -8,6 +8,7 @@ describe OptParseValidator::OptURI do
|
|
8
8
|
describe '#new, #allowed_protocols' do
|
9
9
|
context 'when no attrs supplied' do
|
10
10
|
its(:allowed_protocols) { should be_empty }
|
11
|
+
its(:default_protocol) { should be nil }
|
11
12
|
end
|
12
13
|
|
13
14
|
context 'when only one protocol supplied' do
|
@@ -29,7 +30,7 @@ describe OptParseValidator::OptURI do
|
|
29
30
|
end
|
30
31
|
|
31
32
|
describe '#validate' do
|
32
|
-
context 'when
|
33
|
+
context 'when allowed_protocols is empty' do
|
33
34
|
it 'accepts all protocols' do
|
34
35
|
%w(http ftp file).each do |p|
|
35
36
|
expected = "#{p}://testing"
|
@@ -53,6 +54,22 @@ describe OptParseValidator::OptURI do
|
|
53
54
|
expect(opt.validate(expected)).to eq expected
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
context 'when default_protocol' do
|
59
|
+
let(:attrs) { { default_protocol: 'ftp' } }
|
60
|
+
|
61
|
+
context 'when the argument already contains a protocol' do
|
62
|
+
it 'does not add the default protocol' do
|
63
|
+
expect(opt.validate('http://ex.lo')).to eq 'http://ex.lo'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when no protocol given in the argument' do
|
68
|
+
it 'adds it' do
|
69
|
+
expect(opt.validate('ex.lo')).to eq 'ftp://ex.lo'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
56
73
|
end
|
57
74
|
|
58
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opt_parse_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WPScanTeam - Erwan le Rousseau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|