linkhum-url 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/linkhum/url.rb +17 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0399dffb1cce6eee486039ef1d8415ebb2a1347f'
|
4
|
+
data.tar.gz: 265d932f96994dec962cd2aae4ad45e0b57ff169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5632e26868294c54e6f87aeb8b27a3649932eeaa57c2f44ac4eb5b16a72876c5ec0683faa773f7245c53f63589f10f92e9128999b2abb9efe2819d3e4819758e
|
7
|
+
data.tar.gz: 6beccc5cdb476b11184d915750f9bd18fec1f5e7e4d4a13e1af28697a0645fb55c7a2549d7423fdeb8d5b70a90f7f44f30e3a4b88c5b2457a51a6a9b08449632
|
data/CHANGELOG.md
CHANGED
data/lib/linkhum/url.rb
CHANGED
@@ -20,18 +20,17 @@ module Linkhum
|
|
20
20
|
url_encoded[:port] = au.port ? ":#{au.port}" : ""
|
21
21
|
human_readable[:port] = url_encoded[:port]
|
22
22
|
|
23
|
-
human_readable[:path] =
|
23
|
+
human_readable[:path] = unencode_component(au.path, false)
|
24
24
|
# this code handles bug in Addressable::URI (up to 2.5.0), which
|
25
25
|
# converts paths to Unicode NFKC (it should only do that for
|
26
26
|
# hostnames). Patch to Addressable::URI pending.
|
27
27
|
au_path = au.path.dup
|
28
28
|
if au_path =~ /\A[\x00-\x7F]*\z/
|
29
|
-
au_path =
|
29
|
+
au_path = unencode_component(au_path)
|
30
30
|
end
|
31
31
|
au_path.force_encoding(Encoding::ASCII_8BIT)
|
32
|
-
url_encoded[:path] =
|
33
|
-
|
34
|
-
human_readable[:query] = Addressable::URI.unencode_component(au.query)
|
32
|
+
url_encoded[:path] = encode_component(au_path)
|
33
|
+
human_readable[:query] = unencode_component(au.query, false)
|
35
34
|
if au.query
|
36
35
|
decoded_query = human_readable[:query].dup
|
37
36
|
if !decoded_query.force_encoding(Encoding::UTF_8).valid_encoding?
|
@@ -43,11 +42,11 @@ module Linkhum
|
|
43
42
|
# see above
|
44
43
|
au_query = au.query.dup
|
45
44
|
if au_query =~ /\A[\x00-\x7F]*\z/
|
46
|
-
au_query =
|
45
|
+
au_query = unencode_component(au_query)
|
47
46
|
end
|
48
47
|
au_query.force_encoding(Encoding::ASCII_8BIT)
|
49
48
|
end
|
50
|
-
url_encoded[:query] =
|
49
|
+
url_encoded[:query] = encode_component(au_query)
|
51
50
|
|
52
51
|
# fragments do not need to be encoded
|
53
52
|
human_readable[:fragment] = au.fragment
|
@@ -64,5 +63,16 @@ module Linkhum
|
|
64
63
|
fragment_part = parts[:fragment] ? "##{parts[:fragment]}" : ""
|
65
64
|
"#{parts[:scheme]}://#{userinfo_part}#{parts[:host]}#{parts[:port]}#{parts[:path]}#{query_part}#{fragment_part}"
|
66
65
|
end
|
66
|
+
|
67
|
+
def self.encode_component(string, skip_percent_sign = true)
|
68
|
+
chars_to_keep_unencoded = Addressable::URI::CharacterClasses::RESERVED + Addressable::URI::CharacterClasses::UNRESERVED
|
69
|
+
chars_to_keep_unencoded << '\\%' if skip_percent_sign
|
70
|
+
Addressable::URI.encode_component(string, chars_to_keep_unencoded)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.unencode_component(string, skip_special_chars = true)
|
74
|
+
chars_to_keep_encoded = skip_special_chars ? "%#" : ""
|
75
|
+
Addressable::URI.unencode_component(string, String, chars_to_keep_encoded)
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linkhum-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Makhotkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.6.10
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Linkhum-URL creates both URL-encoded and readable versions of URLs
|