linkhum-url 0.1.3 → 0.1.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/linkhum/url.rb +17 -7
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb8c7762ad429c30b01e5fef3c0f00bf6fb0d707
4
- data.tar.gz: e683f0f660e842ddb534b1700dc227ec54285563
3
+ metadata.gz: '0399dffb1cce6eee486039ef1d8415ebb2a1347f'
4
+ data.tar.gz: 265d932f96994dec962cd2aae4ad45e0b57ff169
5
5
  SHA512:
6
- metadata.gz: 7c6376e51aeb013b235862e2b5585d60203e4c72f17a48ac06a8d3a0d1c6bd87c6a87c3a2d4cc66042289a21301c757e31a4075b2133ef2c6e4f606e671dbfd4
7
- data.tar.gz: 5c5e6600911f6f95554a9768d54819e229fb2c46f6122cc73ba644a5f0b2e14b6d67cfad19b07dcb8b4be2e26d70d110dbe0101f6f1f0e110f3de8bb004d1ae9
6
+ metadata.gz: 5632e26868294c54e6f87aeb8b27a3649932eeaa57c2f44ac4eb5b16a72876c5ec0683faa773f7245c53f63589f10f92e9128999b2abb9efe2819d3e4819758e
7
+ data.tar.gz: 6beccc5cdb476b11184d915750f9bd18fec1f5e7e4d4a13e1af28697a0645fb55c7a2549d7423fdeb8d5b70a90f7f44f30e3a4b88c5b2457a51a6a9b08449632
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.1.4:
2
+
3
+ * Handle URLs with hashtags in query strings (tnx @markiz);
4
+
1
5
  0.1.3:
2
6
 
3
7
  * Handle IDNs which begin with ASCII;
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] = Addressable::URI.unencode_component(au.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 = Addressable::URI.unencode_component(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] = Addressable::URI.encode_component(au_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 = Addressable::URI.unencode_component(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] = Addressable::URI.encode_component(au_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.3
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-01-25 00:00:00.000000000 Z
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.5.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