twingly-url 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/twingly/url.rb +53 -36
- data/lib/twingly/url/hasher.rb +2 -0
- data/lib/twingly/version.rb +1 -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: a0bef38a1195e09028dc139154dd6f7a833c9b91
|
4
|
+
data.tar.gz: 9abaafbd41a71c382f9833ddd6f9fcf5cd9ce08c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e3602b1964b3b2b8f1a37b800f551bf316d8304258aeeb11a1ad43235c2ff81a265a640dbaae25540a9a732145af73543685a4e7f06b5115561d704f37d845
|
7
|
+
data.tar.gz: 44904c9aeae8aa885019c4fb646e3da8d6206d15ede5990df2371fdbebcf02ede04ae101557e6ee4b7b2d6f73f8f664643f7d0e9239fdb84f54ff520309af175
|
data/README.md
CHANGED
data/lib/twingly/url.rb
CHANGED
@@ -4,6 +4,7 @@ require "public_suffix"
|
|
4
4
|
|
5
5
|
require_relative "url/null_url"
|
6
6
|
require_relative "url/error"
|
7
|
+
require_relative "version"
|
7
8
|
|
8
9
|
PublicSuffix::List.private_domains = false
|
9
10
|
|
@@ -19,41 +20,66 @@ module Twingly
|
|
19
20
|
IDN::Idna::IdnaError,
|
20
21
|
]
|
21
22
|
|
22
|
-
|
23
|
-
potential_url = String(potential_url)
|
24
|
-
potential_url = potential_url.scrub
|
25
|
-
potential_url = potential_url.strip
|
23
|
+
private_constant :ACCEPTED_SCHEMES, :ENDS_WITH_SLASH, :ERRORS
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
class << self
|
26
|
+
def parse(potential_url)
|
27
|
+
internal_parse(potential_url)
|
28
|
+
rescue Twingly::URL::Error, Twingly::URL::Error::ParseError => error
|
29
|
+
NullURL.new
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def internal_parse(potential_url)
|
33
|
+
addressable_uri = to_addressable_uri(potential_url)
|
34
|
+
raise Twingly::URL::Error::ParseError if addressable_uri.nil?
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
scheme = addressable_uri.scheme
|
37
|
+
raise Twingly::URL::Error::ParseError unless scheme =~ ACCEPTED_SCHEMES
|
38
38
|
|
39
|
-
|
40
|
-
raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?
|
39
|
+
display_uri = addressable_display_uri(addressable_uri)
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
error.extend(Twingly::URL::Error)
|
45
|
-
raise
|
46
|
-
end
|
41
|
+
public_suffix_domain = PublicSuffix.parse(display_uri.host)
|
42
|
+
raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
raise Twingly::URL::Error::ParseError if public_suffix_domain.sld.nil?
|
45
|
+
|
46
|
+
new(addressable_uri, public_suffix_domain)
|
47
|
+
rescue *ERRORS => error
|
48
|
+
error.extend(Twingly::URL::Error)
|
49
|
+
raise
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_addressable_uri(potential_url)
|
53
|
+
if potential_url.is_a?(Addressable::URI)
|
54
|
+
potential_url
|
55
|
+
else
|
56
|
+
potential_url = String(potential_url)
|
57
|
+
potential_url = potential_url.scrub
|
58
|
+
potential_url = potential_url.strip
|
59
|
+
|
60
|
+
Addressable::URI.heuristic_parse(potential_url)
|
61
|
+
end
|
51
62
|
end
|
52
63
|
|
53
|
-
|
54
|
-
|
64
|
+
# Workaround for the following bug in addressable:
|
65
|
+
# https://github.com/sporkmonger/addressable/issues/224
|
66
|
+
def addressable_display_uri(addressable_uri)
|
67
|
+
addressable_uri.display_uri
|
68
|
+
rescue ArgumentError => error
|
69
|
+
if error.message.include?("invalid byte sequence in UTF-8")
|
70
|
+
raise Twingly::URL::Error::ParseError
|
71
|
+
end
|
72
|
+
|
73
|
+
raise
|
55
74
|
end
|
56
75
|
|
76
|
+
private :new
|
77
|
+
private :internal_parse
|
78
|
+
private :to_addressable_uri
|
79
|
+
private :addressable_display_uri
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize(addressable_uri, public_suffix_domain)
|
57
83
|
@addressable_uri = addressable_uri
|
58
84
|
@public_suffix_domain = public_suffix_domain
|
59
85
|
end
|
@@ -63,7 +89,7 @@ module Twingly
|
|
63
89
|
end
|
64
90
|
|
65
91
|
def trd
|
66
|
-
public_suffix_domain.trd
|
92
|
+
public_suffix_domain.trd.to_s
|
67
93
|
end
|
68
94
|
|
69
95
|
def sld
|
@@ -101,7 +127,7 @@ module Twingly
|
|
101
127
|
normalized_url.host = normalized_host
|
102
128
|
normalized_url.path = normalized_path
|
103
129
|
|
104
|
-
self.class.
|
130
|
+
self.class.parse(normalized_url)
|
105
131
|
end
|
106
132
|
|
107
133
|
def normalized_scheme
|
@@ -143,15 +169,6 @@ module Twingly
|
|
143
169
|
sprintf("#<%s:0x%x %s>", self.class.name, __id__, self.to_s)
|
144
170
|
end
|
145
171
|
|
146
|
-
private_class_method \
|
147
|
-
def self.to_addressable_uri(potential_url)
|
148
|
-
if potential_url.is_a?(Addressable::URI)
|
149
|
-
potential_url
|
150
|
-
else
|
151
|
-
Addressable::URI.heuristic_parse(potential_url)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
172
|
private
|
156
173
|
|
157
174
|
attr_reader :addressable_uri, :public_suffix_domain
|
data/lib/twingly/url/hasher.rb
CHANGED
data/lib/twingly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|