tilia-uri 1.0.1 → 1.0.1.1
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/.simplecov +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -2
- data/LICENSE +1 -1
- data/LICENSE.sabre +1 -1
- data/Rakefile +1 -0
- data/lib/tilia/uri.rb +46 -46
- data/lib/tilia/uri/version.rb +1 -1
- data/test/split_test.rb +1 -1
- data/tilia-uri.gemspec +2 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09e0ca42bc4ae761128b569b6b23fee7e0c4c5be
|
4
|
+
data.tar.gz: e552181bbf1a3b8e536fc95eda81fe689e722e75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da688f7e21c205162da6db73304147ea21bb3508259f5e3d9c68cf70717a1ebc26039f027efc744bcd7cc9d5dba5dd4cea19a0bd9a4332e1dde394965ae00ea4
|
7
|
+
data.tar.gz: 5aaaeff5968abee8f4c0581e1c5c570b8b91858ad61706db3294fc45e8bc8001b61e93ab371f812ea41dd6429f7c7dfed14a95af5a67076b4465e612f917412c
|
data/.simplecov
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tilia-uri (1.0.1.1)
|
5
|
+
activesupport (>= 4.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
activesupport (4.2.
|
10
|
+
activesupport (4.2.5.1)
|
5
11
|
i18n (~> 0.7)
|
6
12
|
json (~> 1.7, >= 1.7.7)
|
7
13
|
minitest (~> 5.1)
|
@@ -40,11 +46,11 @@ PLATFORMS
|
|
40
46
|
ruby
|
41
47
|
|
42
48
|
DEPENDENCIES
|
43
|
-
activesupport (~> 4.2)
|
44
49
|
minitest (~> 5.8)
|
45
50
|
rake
|
46
51
|
rubocop (~> 0.34)
|
47
52
|
simplecov (~> 0.10)
|
53
|
+
tilia-uri!
|
48
54
|
yard (~> 0.8)
|
49
55
|
|
50
56
|
BUNDLED WITH
|
data/LICENSE
CHANGED
data/LICENSE.sabre
CHANGED
data/Rakefile
CHANGED
data/lib/tilia/uri.rb
CHANGED
@@ -32,27 +32,27 @@ module Tilia
|
|
32
32
|
|
33
33
|
# If the new path defines a scheme, it's absolute and we can just return
|
34
34
|
# that.
|
35
|
-
return build(delta) if delta[
|
35
|
+
return build(delta) if delta[:scheme]
|
36
36
|
|
37
37
|
new_parts = {}
|
38
38
|
|
39
|
-
new_parts[
|
40
|
-
new_parts[
|
41
|
-
new_parts[
|
39
|
+
new_parts[:scheme] = pick.call(:scheme)
|
40
|
+
new_parts[:host] = pick.call(:host)
|
41
|
+
new_parts[:port] = pick.call(:port)
|
42
42
|
|
43
43
|
path = ''
|
44
|
-
if !delta[
|
44
|
+
if !delta[:path].blank?
|
45
45
|
# If the path starts with a slash
|
46
|
-
if delta[
|
47
|
-
path = delta[
|
46
|
+
if delta[:path][0] == '/'
|
47
|
+
path = delta[:path]
|
48
48
|
else
|
49
49
|
# Removing last component from base path.
|
50
|
-
path = base[
|
50
|
+
path = base[:path]
|
51
51
|
path = path[0...path.rindex('/')] if path.index '/'
|
52
|
-
path += '/' + delta[
|
52
|
+
path += '/' + delta[:path]
|
53
53
|
end
|
54
54
|
else
|
55
|
-
path = base[
|
55
|
+
path = base[:path].blank? ? '/' : base[:path]
|
56
56
|
end
|
57
57
|
|
58
58
|
# Removing .. and .
|
@@ -79,15 +79,15 @@ module Tilia
|
|
79
79
|
path = new_path_parts.join '/'
|
80
80
|
|
81
81
|
# If the source url ended with a /, we want to preserve that.
|
82
|
-
new_parts[
|
83
|
-
if delta[
|
84
|
-
new_parts[
|
85
|
-
elsif !base[
|
82
|
+
new_parts[:path] = path
|
83
|
+
if delta[:query]
|
84
|
+
new_parts[:query] = delta[:query]
|
85
|
+
elsif !base[:query].blank? && delta[:host].blank? && delta[:path].blank?
|
86
86
|
# Keep the old query if host and path didn't change
|
87
|
-
new_parts[
|
87
|
+
new_parts[:query] = base[:query]
|
88
88
|
end
|
89
89
|
|
90
|
-
new_parts[
|
90
|
+
new_parts[:fragment] = delta[:fragment] if delta[:fragment]
|
91
91
|
build(new_parts)
|
92
92
|
end
|
93
93
|
|
@@ -104,8 +104,8 @@ module Tilia
|
|
104
104
|
def self.normalize(uri)
|
105
105
|
parts = parse(uri)
|
106
106
|
|
107
|
-
unless parts[
|
108
|
-
path_parts = parts[
|
107
|
+
unless parts[:path].blank?
|
108
|
+
path_parts = parts[:path].gsub(%r{^/+}, '').split(%r{/})
|
109
109
|
|
110
110
|
new_path_parts = []
|
111
111
|
path_parts.each do |path_part|
|
@@ -120,32 +120,32 @@ module Tilia
|
|
120
120
|
new_path_parts << URI.escape(URI.unescape(path_part), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
121
121
|
end
|
122
122
|
end
|
123
|
-
parts[
|
123
|
+
parts[:path] = '/' + new_path_parts.join('/')
|
124
124
|
end
|
125
125
|
|
126
|
-
if parts[
|
127
|
-
parts[
|
126
|
+
if parts[:scheme]
|
127
|
+
parts[:scheme] = parts[:scheme].downcase
|
128
128
|
default_ports = {
|
129
129
|
'http' => '80',
|
130
130
|
'https' => '443'
|
131
131
|
}
|
132
132
|
|
133
|
-
if !parts[
|
133
|
+
if !parts[:port].blank? && default_ports.key?(parts[:scheme]) && default_ports[parts[:scheme]] == parts[:port]
|
134
134
|
# Removing default ports.
|
135
|
-
parts[
|
135
|
+
parts[:port] = nil
|
136
136
|
end
|
137
137
|
|
138
138
|
# A few HTTP specific rules.
|
139
|
-
case parts[
|
139
|
+
case parts[:scheme]
|
140
140
|
when 'http', 'https'
|
141
|
-
if parts[
|
141
|
+
if parts[:path].blank?
|
142
142
|
# An empty path is equivalent to / in http.
|
143
|
-
parts[
|
143
|
+
parts[:path] = '/'
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
parts[
|
148
|
+
parts[:host] = parts[:host].downcase if parts[:host]
|
149
149
|
|
150
150
|
build(parts)
|
151
151
|
end
|
@@ -157,17 +157,17 @@ module Tilia
|
|
157
157
|
# set by parse_url, which makes it a bit easier to work with.
|
158
158
|
#
|
159
159
|
# @param [String] uri
|
160
|
-
# @return [Hash]
|
160
|
+
# @return [Hash{Symbol => String}]
|
161
161
|
def self.parse(uri)
|
162
162
|
u = ::URI.split(uri)
|
163
163
|
{
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
164
|
+
scheme: u[0],
|
165
|
+
user: u[1],
|
166
|
+
host: u[2],
|
167
|
+
port: u[3],
|
168
|
+
path: u[5] || u[6], # 6 = mailto, opaque
|
169
|
+
query: u[7],
|
170
|
+
fragment: u[8]
|
171
171
|
}
|
172
172
|
end
|
173
173
|
|
@@ -180,16 +180,16 @@ module Tilia
|
|
180
180
|
uri = ''
|
181
181
|
|
182
182
|
authority = ''
|
183
|
-
unless parts[
|
184
|
-
authority = parts[
|
183
|
+
unless parts[:host].blank?
|
184
|
+
authority = parts[:host]
|
185
185
|
|
186
|
-
authority = parts[
|
187
|
-
authority = authority + ':' + parts[
|
186
|
+
authority = parts[:user] + '@' + authority unless parts[:user].blank?
|
187
|
+
authority = authority + ':' + parts[:port].to_s unless parts[:port].blank?
|
188
188
|
end
|
189
189
|
|
190
|
-
unless parts[
|
190
|
+
unless parts[:scheme].blank?
|
191
191
|
# If there's a scheme, there's also a host.
|
192
|
-
uri = parts[
|
192
|
+
uri = parts[:scheme] + ':'
|
193
193
|
end
|
194
194
|
|
195
195
|
unless authority.blank?
|
@@ -197,9 +197,9 @@ module Tilia
|
|
197
197
|
uri += '//' + authority
|
198
198
|
end
|
199
199
|
|
200
|
-
uri += parts[
|
201
|
-
uri += '?' + parts[
|
202
|
-
uri += '#' + parts[
|
200
|
+
uri += parts[:path] unless parts[:path].blank?
|
201
|
+
uri += '?' + parts[:query] unless parts[:query].blank?
|
202
|
+
uri += '#' + parts[:fragment] unless parts[:fragment].blank?
|
203
203
|
|
204
204
|
uri
|
205
205
|
end
|
@@ -219,12 +219,12 @@ module Tilia
|
|
219
219
|
# the end of the string is stripped off.
|
220
220
|
#
|
221
221
|
# @param [String] path
|
222
|
-
# @return [Array]
|
222
|
+
# @return [Array(String, String)]
|
223
223
|
def self.split(path)
|
224
224
|
if path =~ %r{^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$}u
|
225
225
|
[Regexp.last_match[1] || '', Regexp.last_match[2] || '']
|
226
226
|
else
|
227
|
-
[
|
227
|
+
['', '']
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
data/lib/tilia/uri/version.rb
CHANGED
data/test/split_test.rb
CHANGED
data/tilia-uri.gemspec
CHANGED
@@ -9,5 +9,6 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = 'tilia@jakobsack.de'
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.homepage = 'https://github.com/tilia/tilia-uri'
|
12
|
-
|
12
|
+
|
13
|
+
s.add_runtime_dependency 'activesupport', '>= 4.0'
|
13
14
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilia-uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.1
|
4
|
+
version: 1.0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Sack
|
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: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
26
|
+
version: '4.0'
|
27
27
|
description: Functions for making sense out of URIs.
|
28
28
|
email: tilia@jakobsack.de
|
29
29
|
executables: []
|