twingly-url 3.0.2 → 4.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c5e6153a97d4637dce5f7739d0297b760ca41f0
4
- data.tar.gz: 4e05a760b5bb68f2cb0472a01d38e4f3f16cb713
3
+ metadata.gz: a0bef38a1195e09028dc139154dd6f7a833c9b91
4
+ data.tar.gz: 9abaafbd41a71c382f9833ddd6f9fcf5cd9ce08c
5
5
  SHA512:
6
- metadata.gz: 410fd7c6c40896dbe6fc9450f89a97d65b1b53e263ed94e502bb986eb402716fb3366bc40c9b96f02d1458b19458971cd562e653e08345d24ac6c56f20751fd5
7
- data.tar.gz: 94546494a6769b85a8c63fac77364b3a9075d7091198f4914ca065232e42c18310a0e409b2a224a54a199796b68a95cc525361d9839163f28591dbb6570b99b8
6
+ metadata.gz: b4e3602b1964b3b2b8f1a37b800f551bf316d8304258aeeb11a1ad43235c2ff81a265a640dbaae25540a9a732145af73543685a4e7f06b5115561d704f37d845
7
+ data.tar.gz: 44904c9aeae8aa885019c4fb646e3da8d6206d15ede5990df2371fdbebcf02ede04ae101557e6ee4b7b2d6f73f8f664643f7d0e9239fdb84f54ff520309af175
data/README.md CHANGED
@@ -36,7 +36,7 @@ Run tests with
36
36
 
37
37
  You can get some profiling by running
38
38
 
39
- bundle exec rake test:profile
39
+ bundle exec rake profile:normalize
40
40
 
41
41
  Note that this isn't a benchmark, we're using [ruby-prof] which will slow things down.
42
42
 
@@ -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
- def self.parse(potential_url)
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
- internal_parse(potential_url)
28
- rescue Twingly::URL::Error, Twingly::URL::Error::ParseError => error
29
- NullURL.new
30
- end
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
- def self.internal_parse(potential_url)
33
- addressable_uri = to_addressable_uri(potential_url)
34
- raise Twingly::URL::Error::ParseError if addressable_uri.nil?
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
- scheme = addressable_uri.scheme
37
- raise Twingly::URL::Error::ParseError unless scheme =~ ACCEPTED_SCHEMES
36
+ scheme = addressable_uri.scheme
37
+ raise Twingly::URL::Error::ParseError unless scheme =~ ACCEPTED_SCHEMES
38
38
 
39
- public_suffix_domain = PublicSuffix.parse(addressable_uri.display_uri.host)
40
- raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?
39
+ display_uri = addressable_display_uri(addressable_uri)
41
40
 
42
- self.new(addressable_uri, public_suffix_domain)
43
- rescue *ERRORS => error
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
- def initialize(addressable_uri, public_suffix_domain)
49
- unless addressable_uri.is_a?(Addressable::URI)
50
- raise ArgumentError, "First parameter must be an Addressable::URI"
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
- unless public_suffix_domain.is_a?(PublicSuffix::Domain)
54
- raise ArgumentError, "Second parameter must be a PublicSuffix::Domain"
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.internal_parse(normalized_url)
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
@@ -1,5 +1,7 @@
1
1
  require 'digest'
2
2
 
3
+ require_relative "../url"
4
+
3
5
  module Twingly
4
6
  class URL
5
7
  module Hasher
@@ -1,5 +1,5 @@
1
1
  module Twingly
2
2
  class URL
3
- VERSION = "3.0.2"
3
+ VERSION = "4.0.0"
4
4
  end
5
5
  end
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: 3.0.2
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: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable