uri-whatwg_parser 0.1.5 → 0.1.7
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/CHANGELOG.md +11 -0
- data/README.md +1 -3
- data/lib/uri/whatwg_parser/generic.rb +14 -0
- data/lib/uri/whatwg_parser/host_parser.rb +1 -1
- data/lib/uri/whatwg_parser/version.rb +1 -1
- data/lib/uri/whatwg_parser.rb +29 -17
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff938b4f5dd4b3fa34e438b6b4eed8498b93da3c0b2efad53ab17259376dc745
|
|
4
|
+
data.tar.gz: 50574a50b4bc9003d95cad80b41ba433849296bc20fe1ef7f512032e66bc2a2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da00460b289f008965b15bb943a1d1fd21339ce2224fbb2a9b64997d044a38962982d9f90dbda0886888be35b7eea363476fd3da5a532b6d88453c2cdd07923b
|
|
7
|
+
data.tar.gz: fb82af80a91e4e5c96caf0d478e3dd2f7f89181f4ad634c0e65fb9e589de2fdeb04fc12cc97c3a1aa2ed98ed0423670d7de05025f7c5c9dda20e5f466469e9e9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 0.1.7
|
|
2
|
+
|
|
3
|
+
* Allow to call `URI.split` multiple times
|
|
4
|
+
* Fix parsing a username without a password
|
|
5
|
+
* Support `#merge` method
|
|
6
|
+
|
|
7
|
+
## 0.1.6
|
|
8
|
+
|
|
9
|
+
* Fix `opaque` part parsing
|
|
10
|
+
* Correctly join multiple paths
|
|
11
|
+
|
|
1
12
|
## 0.1.5
|
|
2
13
|
|
|
3
14
|
* Remove `ipaddr` dependency
|
data/README.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Ruby implementation of the [WHATWG URL Living Standard](https://url.spec.whatwg.org/).
|
|
4
4
|
|
|
5
|
-
The latest revision that this package implements of the standard is ([
|
|
6
|
-
|
|
7
|
-
NOTE: Some features haven't been implemented yet. Please see the TODO for details.
|
|
5
|
+
The latest revision that this package implements of the standard is ([18 August 2025](https://url.spec.whatwg.org/commit-snapshots/05a5d834deba31622390ee05a3dcbc22496b7bb5/)).
|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
@@ -227,7 +227,7 @@ class URI::WhatwgParser
|
|
|
227
227
|
validation_error = false
|
|
228
228
|
r = 10
|
|
229
229
|
|
|
230
|
-
if str.size >= 2 &&
|
|
230
|
+
if str.size >= 2 && str.start_with?("0x", "0X")
|
|
231
231
|
validation_error = true
|
|
232
232
|
str = str[2..-1]
|
|
233
233
|
r = 16
|
data/lib/uri/whatwg_parser.rb
CHANGED
|
@@ -5,6 +5,7 @@ require_relative "whatwg_parser/error"
|
|
|
5
5
|
require_relative "whatwg_parser/version"
|
|
6
6
|
require_relative "whatwg_parser/parser_helper"
|
|
7
7
|
require_relative "whatwg_parser/host_parser"
|
|
8
|
+
require_relative "whatwg_parser/generic"
|
|
8
9
|
|
|
9
10
|
module URI
|
|
10
11
|
class WhatwgParser
|
|
@@ -35,11 +36,11 @@ module URI
|
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
def parse(uri, base = nil, encoding = Encoding::UTF_8) # :nodoc:
|
|
38
|
-
reset
|
|
39
39
|
URI.for(*self.split(uri, base, encoding))
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def split(uri, base = nil, encoding = Encoding::UTF_8) # :nodoc:
|
|
43
|
+
reset
|
|
43
44
|
@base = nil
|
|
44
45
|
if base != nil
|
|
45
46
|
ary = split(base, nil, encoding)
|
|
@@ -66,7 +67,7 @@ module URI
|
|
|
66
67
|
@pos += 1
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
@parse_result[:userinfo] =
|
|
70
|
+
@parse_result[:userinfo] = [@username, @password].compact.reject(&:empty?).join(":")
|
|
70
71
|
@parse_result[:path] = "/#{@paths.join("/")}" if @paths && !@paths.empty?
|
|
71
72
|
|
|
72
73
|
@parse_result.values
|
|
@@ -126,22 +127,22 @@ module URI
|
|
|
126
127
|
@state = :path_or_authority_state
|
|
127
128
|
@pos += 1
|
|
128
129
|
else
|
|
129
|
-
@parse_result[:
|
|
130
|
+
@parse_result[:opaque] = ""
|
|
130
131
|
@state = :opaque_path_state
|
|
131
132
|
end
|
|
132
133
|
else
|
|
133
134
|
@buffer.clear
|
|
134
|
-
@pos
|
|
135
|
+
@pos = -1
|
|
135
136
|
@state = :no_scheme_state
|
|
136
137
|
end
|
|
137
138
|
end
|
|
138
139
|
|
|
139
140
|
def no_scheme_state(c)
|
|
140
|
-
raise ParseError, "scheme is missing" if @base.nil? || !@base[:opaque].nil? && c != "#"
|
|
141
|
+
raise ParseError, "scheme is missing" if @base.nil? || (!@base[:opaque].nil? && c != "#")
|
|
141
142
|
|
|
142
143
|
if !@base[:opaque].nil? && c == "#"
|
|
143
144
|
@parse_result[:scheme] = @base[:scheme]
|
|
144
|
-
@
|
|
145
|
+
@paths = @base_paths
|
|
145
146
|
@parse_result[:query] = @base[:query]
|
|
146
147
|
@parse_result[:fragment] = nil
|
|
147
148
|
@state = :fragment_state
|
|
@@ -180,10 +181,10 @@ module URI
|
|
|
180
181
|
elsif special_url? && c == "\\"
|
|
181
182
|
@state = :relative_slash_state
|
|
182
183
|
else
|
|
183
|
-
@
|
|
184
|
+
@username, @password = @base[:userinfo].split(":") if @base[:userinfo]
|
|
184
185
|
@parse_result[:host] = @base[:host]
|
|
185
186
|
@parse_result[:port] = @base[:port]
|
|
186
|
-
@
|
|
187
|
+
@paths = @base_paths
|
|
187
188
|
@parse_result[:query] = @base[:query]
|
|
188
189
|
|
|
189
190
|
if c == "?"
|
|
@@ -207,7 +208,7 @@ module URI
|
|
|
207
208
|
elsif c == "/"
|
|
208
209
|
@state = :authority_state
|
|
209
210
|
else
|
|
210
|
-
@
|
|
211
|
+
@username, @password = @base[:userinfo].split(":") if @base[:userinfo]
|
|
211
212
|
@parse_result[:host] = @base[:host]
|
|
212
213
|
@parse_result[:port] = @base[:port]
|
|
213
214
|
@state = :path_state
|
|
@@ -396,7 +397,6 @@ module URI
|
|
|
396
397
|
@paths ||= []
|
|
397
398
|
|
|
398
399
|
if (c.nil? || c == "/") || (special_url? && c == "\/") || (c == "?" || c == "#")
|
|
399
|
-
|
|
400
400
|
if double_dot_path_segments?(@buffer)
|
|
401
401
|
shorten_url_path
|
|
402
402
|
if c != "/" || (special_url? && c == "\/")
|
|
@@ -408,6 +408,7 @@ module URI
|
|
|
408
408
|
if @parse_result[:scheme] == "file" && @paths.empty? && windows_drive_letter?(@buffer)
|
|
409
409
|
@buffer[1] = ":"
|
|
410
410
|
end
|
|
411
|
+
|
|
411
412
|
@paths << @buffer
|
|
412
413
|
end
|
|
413
414
|
|
|
@@ -433,13 +434,13 @@ module URI
|
|
|
433
434
|
@parse_result[:fragment] = nil
|
|
434
435
|
@state = :fragment_state
|
|
435
436
|
elsif c == " "
|
|
436
|
-
if rest.start_with?("?"
|
|
437
|
-
@parse_result[:
|
|
437
|
+
if rest.start_with?("?", "#")
|
|
438
|
+
@parse_result[:opaque] += "%20"
|
|
438
439
|
else
|
|
439
|
-
@parse_result[:
|
|
440
|
+
@parse_result[:opaque] += " "
|
|
440
441
|
end
|
|
441
442
|
elsif !c.nil?
|
|
442
|
-
@parse_result[:
|
|
443
|
+
@parse_result[:opaque] += percent_encode(c, C0_CONTROL_PERCENT_ENCODE_SET, @encoding)
|
|
443
444
|
end
|
|
444
445
|
end
|
|
445
446
|
|
|
@@ -488,15 +489,26 @@ module URI
|
|
|
488
489
|
end
|
|
489
490
|
|
|
490
491
|
def shorten_url_path
|
|
491
|
-
return if @
|
|
492
|
+
return if @paths.nil?
|
|
492
493
|
|
|
493
|
-
return true if @parse_result[:scheme] == "file" && @
|
|
494
|
-
@
|
|
494
|
+
return true if @parse_result[:scheme] == "file" && @paths.length == 1 && normalized_windows_drive_letter?(@paths.first)
|
|
495
|
+
@paths.pop
|
|
495
496
|
end
|
|
496
497
|
|
|
497
498
|
def rest
|
|
498
499
|
@uri[@pos+1..]
|
|
499
500
|
end
|
|
501
|
+
|
|
502
|
+
def convert_to_uri(uri)
|
|
503
|
+
if uri.is_a?(URI::Generic)
|
|
504
|
+
uri
|
|
505
|
+
elsif uri = String.try_convert(uri)
|
|
506
|
+
parse(uri)
|
|
507
|
+
else
|
|
508
|
+
raise ArgumentError,
|
|
509
|
+
"bad argument (expected URI object or URI string)"
|
|
510
|
+
end
|
|
511
|
+
end
|
|
500
512
|
end
|
|
501
513
|
end
|
|
502
514
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uri-whatwg_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yuji Yaginuma
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- Rakefile
|
|
64
64
|
- lib/uri/whatwg_parser.rb
|
|
65
65
|
- lib/uri/whatwg_parser/error.rb
|
|
66
|
+
- lib/uri/whatwg_parser/generic.rb
|
|
66
67
|
- lib/uri/whatwg_parser/host_parser.rb
|
|
67
68
|
- lib/uri/whatwg_parser/parser_helper.rb
|
|
68
69
|
- lib/uri/whatwg_parser/version.rb
|