url_parser 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +17 -0
- data/lib/url_parser.rb +89 -43
- data/lib/url_parser/version.rb +1 -1
- data/spec/url_parser_spec.rb +123 -43
- data/url_parser.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69dee1c0cfaf6d371119bbbc969312ea4ec1632b
|
4
|
+
data.tar.gz: e57b7aea6c0a4ea33e4d4a8fd63954a47385ec73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd283b722a4e5e4a6ac6b66812fad32d138be669c22e87b9c226e0a8aab7fc0ee0ff9b8445ba1d3e5139d9d59ce41b6d26ba864270c201e7742f7ff00e3572a
|
7
|
+
data.tar.gz: 2ba608ea61964843d308a7c88415b7f73509d8f7be4f7541e461faae5989213f4c072b3fe9a071f4f3a521fdef8b1062cb31dca7c3608a515f24d61877cd608e
|
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
end
|
17
|
+
|
data/lib/url_parser.rb
CHANGED
@@ -20,9 +20,29 @@ end
|
|
20
20
|
|
21
21
|
module UrlParser
|
22
22
|
|
23
|
+
# https://secure.wikimedia.org/wikipedia/en/wiki/URI_scheme
|
24
|
+
SCHEMES = [
|
25
|
+
'file', 'ftp', 'gopher', 'h323', 'hdl', 'http', 'https',
|
26
|
+
'imap', 'magnet', 'mailto', 'mms', 'news', 'nntp', 'prospero',
|
27
|
+
'rsync', 'rtsp', 'rtspu', 'sftp', 'shttp', 'sip', 'sips',
|
28
|
+
'snews', 'svn', 'svn+ssh', 'telnet', 'wais',
|
29
|
+
# Unofficial schemes
|
30
|
+
'aim', 'callto', 'cvs', 'facetime', 'feed', 'git', 'gtalk',
|
31
|
+
'irc', 'ircs', 'irc6', 'itms', 'mms', 'msnim', 'mvn', 'skype',
|
32
|
+
'ssh', 'smb', 'svn', 'ymsg', 'webcal'
|
33
|
+
]
|
34
|
+
|
35
|
+
DEFAULT_SCHEMES = [
|
36
|
+
'http', 'https', 'ftp', 'mailto', 'file', 'ssh', 'feed',
|
37
|
+
'cvs', 'git', 'mvn', 'nntp', 'shttp', 'svn', 'webcal'
|
38
|
+
]
|
23
39
|
|
24
40
|
module Error; end
|
25
41
|
|
42
|
+
class InvalidScheme
|
43
|
+
include UrlParser::Error
|
44
|
+
end
|
45
|
+
|
26
46
|
def self.call(text, options = {})
|
27
47
|
urls = []
|
28
48
|
PostRank::URI.extract(text).each do |url|
|
@@ -37,45 +57,29 @@ module UrlParser
|
|
37
57
|
|
38
58
|
class Base
|
39
59
|
|
40
|
-
|
41
|
-
MAJOR_SCHEMES = [
|
42
|
-
'file', 'ftp', 'gopher', 'h323', 'hdl', 'http', 'https', 'imap', 'magnet',
|
43
|
-
'mailto', 'mms', 'news', 'nntp', 'prospero', 'rsync', 'rtsp', 'rtspu',
|
44
|
-
'sftp', 'shttp', 'sip', 'sips', 'snews', 'svn', 'svn+ssh', 'telnet',
|
45
|
-
'wais',
|
46
|
-
# Unofficial schemes
|
47
|
-
'aim', 'callto', 'cvs', 'facetime', 'feed', 'git', 'gtalk', 'irc', 'ircs',
|
48
|
-
'irc6', 'itms', 'mms', 'msnim', 'skype', 'ssh', 'smb', 'svn', 'ymsg', 'mvn'
|
49
|
-
]
|
50
|
-
|
51
|
-
DEFAULT_SCHEMES = [
|
52
|
-
'http', 'https', 'ftp', 'mailto', 'file', 'ssh', 'feed',
|
53
|
-
'cvs', 'git', 'mvn', 'nntp', 'shttp', 'svn'
|
54
|
-
]
|
60
|
+
attr_reader :url, :original_url, :raise_errors
|
55
61
|
|
56
|
-
|
62
|
+
attr_accessor :errors
|
57
63
|
|
58
64
|
def initialize(url, options = {})
|
59
|
-
@schemes
|
60
|
-
@clean
|
61
|
-
@
|
62
|
-
@
|
65
|
+
@schemes = options.fetch(:schemes) { UrlParser::DEFAULT_SCHEMES }
|
66
|
+
@clean = options.fetch(:clean) { false }
|
67
|
+
@raise_errors = options.fetch(:raise_errors) { false }
|
68
|
+
@errors = []
|
69
|
+
@original_url = url
|
70
|
+
@url = @clean ? clean(url) : parse(url)
|
71
|
+
prepare
|
63
72
|
end
|
64
73
|
|
65
74
|
def schemes
|
66
75
|
Array.wrap(@schemes)
|
67
76
|
end
|
68
77
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def clean(url)
|
76
|
-
tag_errors do
|
77
|
-
PostRank::URI.clean(url, raw: true)
|
78
|
-
end
|
78
|
+
def clean!
|
79
|
+
@parser = nil
|
80
|
+
@url = clean(url)
|
81
|
+
@clean = true
|
82
|
+
self
|
79
83
|
end
|
80
84
|
|
81
85
|
def parser
|
@@ -84,18 +88,13 @@ module UrlParser
|
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
87
|
-
def clean!
|
88
|
-
@parser = nil
|
89
|
-
@url = clean(url)
|
90
|
-
@clean = true
|
91
|
-
self
|
92
|
-
end
|
93
|
-
|
94
91
|
def to_s
|
92
|
+
return '' if errors.any?
|
95
93
|
url.to_s
|
96
94
|
end
|
97
95
|
|
98
96
|
def hash(options = {})
|
97
|
+
return nil if errors.any?
|
99
98
|
clean = options.fetch(:clean) { nil }
|
100
99
|
if clean.nil?
|
101
100
|
Digest::SHA1.hexdigest(url.to_s)
|
@@ -107,13 +106,11 @@ module UrlParser
|
|
107
106
|
end
|
108
107
|
|
109
108
|
def valid?
|
110
|
-
|
111
|
-
return false unless schemes.include?(scheme)
|
112
|
-
return false unless hostname =~ /\./
|
113
|
-
true
|
109
|
+
errors.empty?
|
114
110
|
end
|
115
111
|
|
116
112
|
def join(relative_path)
|
113
|
+
return nil if errors.any?
|
117
114
|
UrlParser.new(
|
118
115
|
Addressable::URI.join(url, relative_path).to_s
|
119
116
|
)
|
@@ -122,29 +119,35 @@ module UrlParser
|
|
122
119
|
# URI Components
|
123
120
|
|
124
121
|
def scheme
|
122
|
+
return nil if errors.any?
|
125
123
|
url.scheme
|
126
124
|
end
|
127
125
|
|
128
126
|
def username
|
127
|
+
return nil if errors.any?
|
129
128
|
url.user
|
130
129
|
end
|
131
130
|
alias_method :user, :username
|
132
131
|
|
133
132
|
def password
|
133
|
+
return nil if errors.any?
|
134
134
|
url.password
|
135
135
|
end
|
136
136
|
|
137
137
|
def userinfo
|
138
|
+
return nil if errors.any?
|
138
139
|
url.userinfo
|
139
140
|
end
|
140
141
|
|
141
142
|
def www
|
143
|
+
return nil if errors.any?
|
142
144
|
return nil if parser.subdomain.empty?
|
143
145
|
parts = slice_domain.split('.')
|
144
146
|
parts.first =~ /www?\d*/ ? parts.shift : nil
|
145
147
|
end
|
146
148
|
|
147
149
|
def subdomain
|
150
|
+
return nil if errors.any?
|
148
151
|
return nil if parser.subdomain.empty?
|
149
152
|
parts = slice_domain.split('.')
|
150
153
|
parts.shift if parts.first =~ /www?\d*/
|
@@ -152,15 +155,18 @@ module UrlParser
|
|
152
155
|
end
|
153
156
|
|
154
157
|
def subdomains
|
158
|
+
return nil if errors.any?
|
155
159
|
return nil if parser.subdomain.empty?
|
156
160
|
[ www, subdomain ].compact.join('.')
|
157
161
|
end
|
158
162
|
|
159
163
|
def domain_name
|
164
|
+
return nil if errors.any?
|
160
165
|
parser.domain.empty? ? nil : parser.domain
|
161
166
|
end
|
162
167
|
|
163
168
|
def domain
|
169
|
+
return nil if errors.any?
|
164
170
|
if parser.domain_with_public_suffix.empty?
|
165
171
|
nil
|
166
172
|
else
|
@@ -169,36 +175,44 @@ module UrlParser
|
|
169
175
|
end
|
170
176
|
|
171
177
|
def tld
|
178
|
+
return nil if errors.any?
|
172
179
|
tld = parser.public_suffix
|
173
180
|
tld.empty? ? nil : tld
|
174
181
|
end
|
175
182
|
|
176
183
|
def hostname
|
184
|
+
return nil if errors.any?
|
177
185
|
url.host
|
178
186
|
end
|
179
187
|
|
180
188
|
def port
|
189
|
+
return nil if errors.any?
|
181
190
|
url.port
|
182
191
|
end
|
183
192
|
|
184
193
|
def host
|
194
|
+
return nil if errors.any?
|
185
195
|
name = [ hostname, port ].compact.join(':')
|
186
196
|
name.empty? ? nil : name
|
187
197
|
end
|
188
198
|
|
189
199
|
def origin
|
200
|
+
return nil if errors.any?
|
190
201
|
url.origin == "null" ? nil : url.origin
|
191
202
|
end
|
192
203
|
|
193
204
|
def authority
|
205
|
+
return nil if errors.any?
|
194
206
|
url.authority
|
195
207
|
end
|
196
208
|
|
197
209
|
def site
|
210
|
+
return nil if errors.any?
|
198
211
|
url.site
|
199
212
|
end
|
200
213
|
|
201
214
|
def directory
|
215
|
+
return nil if errors.any?
|
202
216
|
parts = path.split('/')
|
203
217
|
return '/' if parts.empty?
|
204
218
|
parts.pop unless segment.to_s.empty?
|
@@ -207,38 +221,46 @@ module UrlParser
|
|
207
221
|
end
|
208
222
|
|
209
223
|
def path
|
224
|
+
return nil if errors.any?
|
210
225
|
url.path
|
211
226
|
end
|
212
227
|
|
213
228
|
def segment
|
229
|
+
return nil if errors.any?
|
214
230
|
path =~ /\/\z/ ? nil : path.split('/').last
|
215
231
|
end
|
216
232
|
|
217
233
|
def filename
|
234
|
+
return nil if errors.any?
|
218
235
|
return 'index.html' if segment.to_s.empty?
|
219
236
|
return '' if suffix.to_s.empty?
|
220
237
|
segment
|
221
238
|
end
|
222
239
|
|
223
240
|
def suffix
|
241
|
+
return nil if errors.any?
|
224
242
|
ext = File.extname(path)
|
225
243
|
ext[0] = '' if ext[0] == '.'
|
226
244
|
ext.empty? ? nil : ext
|
227
245
|
end
|
228
246
|
|
229
247
|
def query
|
248
|
+
return nil if errors.any?
|
230
249
|
url.query
|
231
250
|
end
|
232
251
|
|
233
252
|
def query_values
|
253
|
+
return {} if errors.any?
|
234
254
|
url.query_values.to_h
|
235
255
|
end
|
236
256
|
|
237
257
|
def fragment
|
258
|
+
return nil if errors.any?
|
238
259
|
url.fragment
|
239
260
|
end
|
240
261
|
|
241
262
|
def resource
|
263
|
+
return nil if errors.any?
|
242
264
|
name = [
|
243
265
|
[ segment, query ].compact.join('?'), fragment
|
244
266
|
].compact.join('#')
|
@@ -246,14 +268,17 @@ module UrlParser
|
|
246
268
|
end
|
247
269
|
|
248
270
|
def relative?
|
271
|
+
return nil if errors.any?
|
249
272
|
url.relative?
|
250
273
|
end
|
251
274
|
|
252
275
|
def absolute?
|
276
|
+
return nil if errors.any?
|
253
277
|
url.absolute?
|
254
278
|
end
|
255
279
|
|
256
280
|
def localhost?
|
281
|
+
return nil if errors.any?
|
257
282
|
!!(hostname =~ /(\A|\.)localhost\z/)
|
258
283
|
end
|
259
284
|
|
@@ -266,8 +291,29 @@ module UrlParser
|
|
266
291
|
def tag_errors
|
267
292
|
yield
|
268
293
|
rescue Exception => error
|
269
|
-
error.
|
270
|
-
|
294
|
+
unless error.singleton_class.include?(UrlParser::Error)
|
295
|
+
error.extend(UrlParser::Error)
|
296
|
+
end
|
297
|
+
@errors << error
|
298
|
+
raise if raise_errors
|
299
|
+
end
|
300
|
+
|
301
|
+
def parse(url)
|
302
|
+
tag_errors do
|
303
|
+
PostRank::URI.parse(url, raw: true)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def clean(url)
|
308
|
+
tag_errors do
|
309
|
+
PostRank::URI.clean(url, raw: true)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
# Initialize parser to ensure no errors are raised
|
314
|
+
#
|
315
|
+
def prepare
|
316
|
+
parser
|
271
317
|
end
|
272
318
|
|
273
319
|
end
|
data/lib/url_parser/version.rb
CHANGED
data/spec/url_parser_spec.rb
CHANGED
@@ -8,6 +8,18 @@ describe UrlParser do
|
|
8
8
|
expect(UrlParser::VERSION).not_to be_nil
|
9
9
|
end
|
10
10
|
|
11
|
+
context "::SCHEMES" do
|
12
|
+
|
13
|
+
it { expect( UrlParser::SCHEMES).to be_an Array }
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "::DEFAULT_SCHEMES" do
|
18
|
+
|
19
|
+
it { expect( UrlParser::DEFAULT_SCHEMES).to be_an Array }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
11
23
|
context "::call" do
|
12
24
|
|
13
25
|
let(:link) { 'http://example.com/' }
|
@@ -33,10 +45,6 @@ describe UrlParser do
|
|
33
45
|
expect(parser.to_s).to eq link
|
34
46
|
end
|
35
47
|
|
36
|
-
it "cannot initialize invalid urls" do
|
37
|
-
expect{ UrlParser.new('http:||bra.ziz') }.to raise_error
|
38
|
-
end
|
39
|
-
|
40
48
|
it "adds http by default" do
|
41
49
|
expect(UrlParser.new('example.com/path').to_s).to eq link
|
42
50
|
end
|
@@ -45,10 +53,12 @@ describe UrlParser do
|
|
45
53
|
expect(UrlParser.new('//example.com/path').to_s).to eq link
|
46
54
|
end
|
47
55
|
|
48
|
-
it "
|
49
|
-
expect
|
50
|
-
|
51
|
-
|
56
|
+
it "cannot initialize invalid urls" do
|
57
|
+
expect(UrlParser.new('http:||bra.ziz').url).to be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "catches errors from invalid urls" do
|
61
|
+
expect(UrlParser.new('http:||bra.ziz').errors).not_to be_empty
|
52
62
|
end
|
53
63
|
|
54
64
|
context "options" do
|
@@ -81,6 +91,22 @@ describe UrlParser do
|
|
81
91
|
|
82
92
|
end
|
83
93
|
|
94
|
+
context ":raise_errors" do
|
95
|
+
|
96
|
+
it "raises instead of catching errors" do
|
97
|
+
expect{
|
98
|
+
UrlParser.new('http:||bra.ziz', raise_errors: true)
|
99
|
+
}.to raise_error
|
100
|
+
end
|
101
|
+
|
102
|
+
it "any errors raised inherit from UrlParser::Error" do
|
103
|
+
expect{
|
104
|
+
UrlParser.new('http:||bra.ziz', raise_errors: true)
|
105
|
+
}.to raise_error UrlParser::Error
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
84
110
|
end
|
85
111
|
|
86
112
|
end
|
@@ -123,10 +149,10 @@ describe UrlParser do
|
|
123
149
|
UrlParser.new(link, clean: false)
|
124
150
|
end
|
125
151
|
|
126
|
-
it "tags errors" do
|
127
|
-
parser = UrlParser.new(link, clean: true)
|
152
|
+
it "tags errors when set to raise errors" do
|
153
|
+
parser = UrlParser.new(link, clean: true, raise_errors: true)
|
128
154
|
expect(PostRank::URI).to receive(:parse).and_raise(StandardError)
|
129
|
-
expect{ parser.parse
|
155
|
+
expect{ parser.send(:parse, link) }.to raise_error UrlParser::Error
|
130
156
|
end
|
131
157
|
|
132
158
|
end
|
@@ -141,9 +167,9 @@ describe UrlParser do
|
|
141
167
|
end
|
142
168
|
|
143
169
|
it "tags errors" do
|
144
|
-
parser = UrlParser.new(link, clean: false)
|
170
|
+
parser = UrlParser.new(link, clean: false, raise_errors: true)
|
145
171
|
expect(PostRank::URI).to receive(:clean).and_raise(StandardError)
|
146
|
-
expect{ parser.clean
|
172
|
+
expect{ parser.send(:clean, link) }.to raise_error UrlParser::Error
|
147
173
|
end
|
148
174
|
|
149
175
|
end
|
@@ -153,15 +179,15 @@ describe UrlParser do
|
|
153
179
|
let(:link) { 'link.to?a=b&utm_source=FeedBurner#stuff' }
|
154
180
|
|
155
181
|
it "calls postrank-uri's clean function" do
|
156
|
-
parser = UrlParser.new(link, clean: true)
|
157
182
|
expect(Domainatrix).to receive(:parse).with(parser.to_s)
|
158
|
-
|
183
|
+
UrlParser.new(link, clean: true)
|
159
184
|
end
|
160
185
|
|
161
186
|
it "tags errors" do
|
162
|
-
parser = UrlParser.new(link, clean: false)
|
163
187
|
expect(Domainatrix).to receive(:parse).and_raise(StandardError)
|
164
|
-
expect{
|
188
|
+
expect{
|
189
|
+
UrlParser.new(link, clean: false, raise_errors: true)
|
190
|
+
}.to raise_error UrlParser::Error
|
165
191
|
end
|
166
192
|
|
167
193
|
end
|
@@ -208,24 +234,12 @@ describe UrlParser do
|
|
208
234
|
|
209
235
|
context "#valid?" do
|
210
236
|
|
211
|
-
it "returns
|
212
|
-
expect(UrlParser.new('
|
213
|
-
end
|
214
|
-
|
215
|
-
it "returns false if the url scheme is not in the options" do
|
216
|
-
expect(UrlParser.new('telnet://some.com')).not_to be_valid
|
217
|
-
end
|
218
|
-
|
219
|
-
it "returns true if the url scheme is in the options" do
|
220
|
-
expect(UrlParser.new('telnet://some.com', schemes: ['telnet'])).to be_valid
|
221
|
-
end
|
222
|
-
|
223
|
-
it "returns true if the url is valid" do
|
224
|
-
expect(UrlParser.new('http://example.com/')).to be_valid
|
237
|
+
it "returns true if there are no errors" do
|
238
|
+
expect(UrlParser.new('http://example.com')).to be_valid
|
225
239
|
end
|
226
240
|
|
227
|
-
it "returns
|
228
|
-
expect(UrlParser.new('
|
241
|
+
it "returns false if there are errors" do
|
242
|
+
expect(UrlParser.new('http:||bra.ziz')).not_to be_valid
|
229
243
|
end
|
230
244
|
|
231
245
|
end
|
@@ -273,13 +287,15 @@ describe UrlParser do
|
|
273
287
|
|
274
288
|
let(:parser) { UrlParser.new(link, clean: false) }
|
275
289
|
|
276
|
-
context "when present" do
|
290
|
+
context "when all are present" do
|
277
291
|
|
278
292
|
let(:link) do
|
279
|
-
'
|
293
|
+
'https://username:password@ww2.foo.bar.example.com:123/hello/world/there.html?name=ferret#foo'
|
280
294
|
end
|
281
295
|
|
282
|
-
it { expect(parser.
|
296
|
+
it { expect(parser.errors).to be_empty }
|
297
|
+
it { expect(parser).to be_valid }
|
298
|
+
it { expect(parser.scheme).to eq 'https' }
|
283
299
|
it { expect(parser.username).to eq 'username' }
|
284
300
|
it { expect(parser.password).to eq 'password' }
|
285
301
|
it { expect(parser.userinfo).to eq 'username:password' }
|
@@ -292,9 +308,9 @@ describe UrlParser do
|
|
292
308
|
it { expect(parser.hostname).to eq 'ww2.foo.bar.example.com' }
|
293
309
|
it { expect(parser.port).to eq 123 }
|
294
310
|
it { expect(parser.host).to eq 'ww2.foo.bar.example.com:123' }
|
295
|
-
it { expect(parser.origin).to eq '
|
311
|
+
it { expect(parser.origin).to eq 'https://ww2.foo.bar.example.com:123' }
|
296
312
|
it { expect(parser.authority).to eq 'username:password@ww2.foo.bar.example.com:123' }
|
297
|
-
it { expect(parser.site).to eq '
|
313
|
+
it { expect(parser.site).to eq 'https://username:password@ww2.foo.bar.example.com:123' }
|
298
314
|
it { expect(parser.directory).to eq '/hello/world' }
|
299
315
|
it { expect(parser.path).to eq '/hello/world/there.html' }
|
300
316
|
it { expect(parser.segment).to eq 'there.html' }
|
@@ -304,15 +320,13 @@ describe UrlParser do
|
|
304
320
|
it { expect(parser.query_values['name']).to eq 'ferret' }
|
305
321
|
it { expect(parser.fragment).to eq 'foo' }
|
306
322
|
it { expect(parser.resource).to eq 'there.html?name=ferret#foo' }
|
307
|
-
|
308
323
|
end
|
309
324
|
|
310
|
-
context "when
|
325
|
+
context "when none are present" do
|
311
326
|
|
312
|
-
let(:link)
|
313
|
-
'/'
|
314
|
-
end
|
327
|
+
let(:link) { '/' }
|
315
328
|
|
329
|
+
it { expect(parser.errors).to be_empty }
|
316
330
|
it { expect(parser.scheme).to be_nil }
|
317
331
|
it { expect(parser.username).to be_nil }
|
318
332
|
it { expect(parser.password).to be_nil }
|
@@ -341,6 +355,72 @@ describe UrlParser do
|
|
341
355
|
|
342
356
|
end
|
343
357
|
|
358
|
+
context "when empty" do
|
359
|
+
|
360
|
+
let(:link) { '' }
|
361
|
+
|
362
|
+
it { expect(parser.errors).to be_empty }
|
363
|
+
it { expect(parser.scheme).to be_nil }
|
364
|
+
it { expect(parser.username).to be_nil }
|
365
|
+
it { expect(parser.password).to be_nil }
|
366
|
+
it { expect(parser.userinfo).to be_nil }
|
367
|
+
it { expect(parser.www).to be_nil }
|
368
|
+
it { expect(parser.subdomain).to be_nil }
|
369
|
+
it { expect(parser.subdomains).to be_nil }
|
370
|
+
it { expect(parser.domain_name).to be_nil }
|
371
|
+
it { expect(parser.domain).to be_nil }
|
372
|
+
it { expect(parser.tld).to be_nil }
|
373
|
+
it { expect(parser.hostname).to be_nil }
|
374
|
+
it { expect(parser.port).to be_nil }
|
375
|
+
it { expect(parser.host).to be_nil }
|
376
|
+
it { expect(parser.origin).to be_nil }
|
377
|
+
it { expect(parser.authority).to be_nil }
|
378
|
+
it { expect(parser.site).to be_nil }
|
379
|
+
it { expect(parser.directory).to eq '/' }
|
380
|
+
it { expect(parser.path).to eq '' }
|
381
|
+
it { expect(parser.segment).to be_nil }
|
382
|
+
it { expect(parser.filename).to eq 'index.html' }
|
383
|
+
it { expect(parser.suffix).to be_nil }
|
384
|
+
it { expect(parser.query).to be_nil }
|
385
|
+
it { expect(parser.query_values['name']).to be_nil }
|
386
|
+
it { expect(parser.fragment).to be_nil }
|
387
|
+
it { expect(parser.resource).to be_nil }
|
388
|
+
|
389
|
+
end
|
390
|
+
|
391
|
+
context "when invalid" do
|
392
|
+
|
393
|
+
let(:link) { 'http://#content-zone' }
|
394
|
+
|
395
|
+
it { expect(parser.errors).not_to be_empty }
|
396
|
+
it { expect(parser.scheme).to be_nil }
|
397
|
+
it { expect(parser.username).to be_nil }
|
398
|
+
it { expect(parser.password).to be_nil }
|
399
|
+
it { expect(parser.userinfo).to be_nil }
|
400
|
+
it { expect(parser.www).to be_nil }
|
401
|
+
it { expect(parser.subdomain).to be_nil }
|
402
|
+
it { expect(parser.subdomains).to be_nil }
|
403
|
+
it { expect(parser.domain_name).to be_nil }
|
404
|
+
it { expect(parser.domain).to be_nil }
|
405
|
+
it { expect(parser.tld).to be_nil }
|
406
|
+
it { expect(parser.hostname).to be_nil }
|
407
|
+
it { expect(parser.port).to be_nil }
|
408
|
+
it { expect(parser.host).to be_nil }
|
409
|
+
it { expect(parser.origin).to be_nil }
|
410
|
+
it { expect(parser.authority).to be_nil }
|
411
|
+
it { expect(parser.site).to be_nil }
|
412
|
+
it { expect(parser.directory).to be_nil }
|
413
|
+
it { expect(parser.path).to be_nil }
|
414
|
+
it { expect(parser.segment).to be_nil }
|
415
|
+
it { expect(parser.filename).to be_nil }
|
416
|
+
it { expect(parser.suffix).to be_nil }
|
417
|
+
it { expect(parser.query).to be_nil }
|
418
|
+
it { expect(parser.query_values['name']).to be_nil }
|
419
|
+
it { expect(parser.fragment).to be_nil }
|
420
|
+
it { expect(parser.resource).to be_nil }
|
421
|
+
|
422
|
+
end
|
423
|
+
|
344
424
|
end
|
345
425
|
|
346
426
|
context "localhost?" do
|
data/url_parser.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake", "~> 10"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
24
25
|
spec.add_development_dependency "pry"
|
25
26
|
|
26
27
|
spec.add_dependency "domainatrix", ">= 0.0.11"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Solt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +133,7 @@ files:
|
|
119
133
|
- ".gitignore"
|
120
134
|
- ".rspec"
|
121
135
|
- Gemfile
|
136
|
+
- Guardfile
|
122
137
|
- LICENSE.txt
|
123
138
|
- README.md
|
124
139
|
- Rakefile
|