uri-whatwg_parser 0.3.0 → 0.3.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/CHANGELOG.md +6 -0
- data/README.md +0 -5
- data/lib/uri/whatwg_parser/generic.rb +2 -2
- data/lib/uri/whatwg_parser/version.rb +1 -1
- data/lib/uri/whatwg_parser.rb +25 -20
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 340c89cc9b0c80699547d7daa0a33c3c081250ebee1dd1178a36ee288a484a22
|
|
4
|
+
data.tar.gz: 961034f93393490c76ad015aea1524b27b5955ef38112892d50b2a1e15a3ac50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 987525847dbe6f04d4a2a4c3c8e338d57ebd964d4312528bc16e5e515ba7460922c3fedf08a4151227dbd1fbca11be4af38db6db53e1d741992460fd89c86bd0
|
|
7
|
+
data.tar.gz: 12eae3fe44a8136aa66a55d1aa7e12b172980ae96470f890e34e721fae4c1f3f23155ff1a2e1db305ce2f239cdf239a7db43fe5feb153eb11f3f230c09fd77a4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# URI::WhatwgParser
|
|
2
|
-
|
|
3
2
|
Ruby implementation of the [WHATWG URL Living Standard](https://url.spec.whatwg.org/).
|
|
4
3
|
|
|
5
4
|
The latest revision that this package implements of the standard is [14 April 2026](https://url.spec.whatwg.org/commit-snapshots/b11d73b8caefe90403afe19210db05acba897722/)
|
|
@@ -27,10 +26,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
|
27
26
|
|
|
28
27
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
29
28
|
|
|
30
|
-
## TODO
|
|
31
|
-
|
|
32
|
-
* Support validations
|
|
33
|
-
|
|
34
29
|
## Contributing
|
|
35
30
|
|
|
36
31
|
Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/uri-whatwg_parser.
|
|
@@ -6,7 +6,7 @@ module URI
|
|
|
6
6
|
def initialize(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser = DEFAULT_PARSER, arg_check = false)
|
|
7
7
|
@parsed_by_whatwg_parser = parser.is_a?(URI::WhatwgParser)
|
|
8
8
|
unless parser.is_a?(URI::WhatwgParser)
|
|
9
|
-
return super(scheme, userinfo, host, port, registry, path, opaque, query, fragment)
|
|
9
|
+
return super(scheme, userinfo, host, port, registry, path, opaque, query, fragment, URI::RFC3986_PARSER, arg_check)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
@scheme = nil
|
|
@@ -26,7 +26,7 @@ module URI
|
|
|
26
26
|
self.set_port(port)
|
|
27
27
|
self.set_userinfo(userinfo)
|
|
28
28
|
self.set_path(path)
|
|
29
|
-
|
|
29
|
+
@query = query
|
|
30
30
|
self.set_opaque(opaque)
|
|
31
31
|
@fragment = fragment
|
|
32
32
|
@raw_path = parser&.path
|
data/lib/uri/whatwg_parser.rb
CHANGED
|
@@ -25,7 +25,7 @@ module URI
|
|
|
25
25
|
|
|
26
26
|
WINDOWS_DRIVE_LETTER = Regexp.new("\\A([a-zA-Z][:|])\\z")
|
|
27
27
|
NORMALIZED_WINDOWS_DRIVE_LETTER = Regexp.new("\\A([a-zA-Z][:])\\z")
|
|
28
|
-
|
|
28
|
+
FILE_OTHERWISE_CODE_POINTS = Set["/", "\\", "?", "#"]
|
|
29
29
|
|
|
30
30
|
VALID_SIGNS_FOR_SCHEME = Set["+", "-", "."]
|
|
31
31
|
DELIMITER_SIGNS = Set["/", "?", "#"]
|
|
@@ -96,7 +96,11 @@ module URI
|
|
|
96
96
|
@pos += 1
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
if @password
|
|
100
|
+
userinfo = "#{@username}:#{@password}"
|
|
101
|
+
else
|
|
102
|
+
userinfo = @username
|
|
103
|
+
end
|
|
100
104
|
if @path
|
|
101
105
|
if @path.is_a?(Array)
|
|
102
106
|
path = "/#{@path.join("/")}"
|
|
@@ -235,7 +239,7 @@ module URI
|
|
|
235
239
|
@special_url = special_url?(@base[:scheme])
|
|
236
240
|
@path = @base_path
|
|
237
241
|
@parse_result[:query] = @base[:query]
|
|
238
|
-
@parse_result[:fragment] =
|
|
242
|
+
@parse_result[:fragment] = +""
|
|
239
243
|
@state = :fragment_state
|
|
240
244
|
elsif @base[:scheme] != "file"
|
|
241
245
|
@state = :relative_state
|
|
@@ -280,10 +284,10 @@ module URI
|
|
|
280
284
|
@parse_result[:query] = @base[:query]
|
|
281
285
|
|
|
282
286
|
if c == "?"
|
|
283
|
-
@parse_result[:query] =
|
|
287
|
+
@parse_result[:query] = +""
|
|
284
288
|
@state = :query_state
|
|
285
289
|
elsif c == "#"
|
|
286
|
-
@parse_result[:fragment] =
|
|
290
|
+
@parse_result[:fragment] = +""
|
|
287
291
|
@state = :fragment_state
|
|
288
292
|
elsif !c.nil?
|
|
289
293
|
@parse_result[:query] = nil
|
|
@@ -394,7 +398,7 @@ module URI
|
|
|
394
398
|
@buffer << c
|
|
395
399
|
elsif c.nil? || DELIMITER_SIGNS.include?(c) || (@special_url && c == "\\") || @state_override
|
|
396
400
|
unless @buffer.empty?
|
|
397
|
-
port =
|
|
401
|
+
port = @buffer.to_i
|
|
398
402
|
raise ParseError, "port is invalid value" if port < 0 || port > 65535
|
|
399
403
|
if SPECIAL_SCHEME[@parse_result[:scheme]] == port
|
|
400
404
|
@parse_result[:port] = nil
|
|
@@ -409,7 +413,6 @@ module URI
|
|
|
409
413
|
end
|
|
410
414
|
end
|
|
411
415
|
|
|
412
|
-
raise ParseError, "port is invalid value" if @state_override
|
|
413
416
|
@state = :path_start_state
|
|
414
417
|
@pos -= 1
|
|
415
418
|
else
|
|
@@ -421,17 +424,17 @@ module URI
|
|
|
421
424
|
@parse_result[:scheme] = "file"
|
|
422
425
|
@special_url = true
|
|
423
426
|
@parse_result[:host] = nil
|
|
424
|
-
|
|
425
427
|
if c == "/" || c == "\\"
|
|
426
428
|
@state = :file_slash_state
|
|
427
429
|
elsif !@base.nil? && @base[:scheme] == "file"
|
|
428
430
|
@parse_result[:host] = @base[:host]
|
|
431
|
+
@path = @base_path
|
|
429
432
|
@parse_result[:query] = @base[:query]
|
|
430
433
|
if c == "?"
|
|
431
|
-
@parse_result[:query] =
|
|
434
|
+
@parse_result[:query] = +""
|
|
432
435
|
@state = :query_state
|
|
433
436
|
elsif c == "#"
|
|
434
|
-
@parse_result[:fragment] =
|
|
437
|
+
@parse_result[:fragment] = +""
|
|
435
438
|
@state = :fragment_state
|
|
436
439
|
elsif !c.nil?
|
|
437
440
|
@parse_result[:query] = nil
|
|
@@ -456,10 +459,8 @@ module URI
|
|
|
456
459
|
if !@base.nil? && @base[:scheme] == "file"
|
|
457
460
|
@parse_result[:host] = @base[:host]
|
|
458
461
|
if !starts_with_windows_drive_letter?(rest) && @base_path && normalized_windows_drive_letter?(@base_path[0])
|
|
459
|
-
if @path.nil?
|
|
460
|
-
|
|
461
|
-
@path[0] = @base_path[0]
|
|
462
|
-
end
|
|
462
|
+
@path = [] if @path.nil?
|
|
463
|
+
@path << @base_path[0]
|
|
463
464
|
end
|
|
464
465
|
end
|
|
465
466
|
@state = :path_state
|
|
@@ -501,8 +502,10 @@ module URI
|
|
|
501
502
|
@pos -= 1 if c != "/" && c != "\\"
|
|
502
503
|
@state = :path_state
|
|
503
504
|
elsif !@state_override && c == "?"
|
|
505
|
+
@parse_result[:query] = +""
|
|
504
506
|
@state = :query_state
|
|
505
507
|
elsif !@state_override && c == "#"
|
|
508
|
+
@parse_result[:fragment] = +""
|
|
506
509
|
@state = :fragment_state
|
|
507
510
|
elsif c != nil
|
|
508
511
|
@pos -= 1 if c != "/"
|
|
@@ -536,10 +539,10 @@ module URI
|
|
|
536
539
|
@buffer = +""
|
|
537
540
|
|
|
538
541
|
if c == "?"
|
|
539
|
-
@parse_result[:query] =
|
|
542
|
+
@parse_result[:query] = +""
|
|
540
543
|
@state = :query_state
|
|
541
544
|
elsif c == "#"
|
|
542
|
-
@parse_result[:fragment] =
|
|
545
|
+
@parse_result[:fragment] = +""
|
|
543
546
|
@state = :fragment_state
|
|
544
547
|
end
|
|
545
548
|
else
|
|
@@ -549,10 +552,10 @@ module URI
|
|
|
549
552
|
|
|
550
553
|
def opaque_path_state(c)
|
|
551
554
|
if c == "?"
|
|
552
|
-
@parse_result[:query] =
|
|
555
|
+
@parse_result[:query] = +""
|
|
553
556
|
@state = :query_state
|
|
554
557
|
elsif c == "#"
|
|
555
|
-
@parse_result[:fragment] =
|
|
558
|
+
@parse_result[:fragment] = +""
|
|
556
559
|
@state = :fragment_state
|
|
557
560
|
elsif c == " "
|
|
558
561
|
first_of_rest = @input_chars[@pos + 1]
|
|
@@ -591,7 +594,9 @@ module URI
|
|
|
591
594
|
end
|
|
592
595
|
|
|
593
596
|
def starts_with_windows_drive_letter?(str)
|
|
594
|
-
|
|
597
|
+
return false if str.length < 2
|
|
598
|
+
return false unless windows_drive_letter?(str[0, 2])
|
|
599
|
+
str.length == 2 || FILE_OTHERWISE_CODE_POINTS.include?(str[2])
|
|
595
600
|
end
|
|
596
601
|
|
|
597
602
|
def normalized_windows_drive_letter?(str)
|
|
@@ -621,7 +626,7 @@ module URI
|
|
|
621
626
|
end
|
|
622
627
|
|
|
623
628
|
def rest
|
|
624
|
-
@input_chars[@pos
|
|
629
|
+
@input_chars[@pos..]&.join
|
|
625
630
|
end
|
|
626
631
|
|
|
627
632
|
def convert_to_uri(uri)
|