uri 0.11.3 → 0.12.5
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/.github/dependabot.yml +6 -0
- data/lib/uri/common.rb +43 -11
- data/lib/uri/file.rb +6 -0
- data/lib/uri/generic.rb +33 -10
- data/lib/uri/mailto.rb +1 -1
- data/lib/uri/rfc3986_parser.rb +1 -2
- data/lib/uri/version.rb +1 -1
- data/lib/uri.rb +1 -0
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 522757d2dcaf03c71cf264ebe70ebc52977e41f0ebdfd571736e75bd68bf8b06
|
|
4
|
+
data.tar.gz: 2b95b950a4c1b64ba908f5bc2faf33994ceabf74a7b00b90df8d1535b77487a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28e9ddf4e9c71eb4e92ceef3cdcf3119b11f722197f39157fa61df13de44d967a4694ee87e6ad0a4d21e0047f12818473914000ebc5d96810dec55544e157b6b
|
|
7
|
+
data.tar.gz: cb098d2164e1dbf3e310ff11fcd9428a1beec85dbcca9b116b2dba7ba0408a82af4a71b5240dfa0a6498bf747360accd7d03d4a89dcb7c2842139430301e4839
|
data/lib/uri/common.rb
CHANGED
|
@@ -13,10 +13,14 @@ require_relative "rfc2396_parser"
|
|
|
13
13
|
require_relative "rfc3986_parser"
|
|
14
14
|
|
|
15
15
|
module URI
|
|
16
|
+
include RFC2396_REGEXP
|
|
17
|
+
|
|
16
18
|
REGEXP = RFC2396_REGEXP
|
|
17
19
|
Parser = RFC2396_Parser
|
|
18
20
|
RFC3986_PARSER = RFC3986_Parser.new
|
|
19
21
|
Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
|
|
22
|
+
RFC2396_PARSER = RFC2396_Parser.new
|
|
23
|
+
Ractor.make_shareable(RFC2396_PARSER) if defined?(Ractor)
|
|
20
24
|
|
|
21
25
|
# URI::Parser.new
|
|
22
26
|
DEFAULT_PARSER = Parser.new
|
|
@@ -62,14 +66,17 @@ module URI
|
|
|
62
66
|
module_function :make_components_hash
|
|
63
67
|
end
|
|
64
68
|
|
|
65
|
-
include REGEXP
|
|
66
|
-
|
|
67
69
|
module Schemes
|
|
68
70
|
end
|
|
69
71
|
private_constant :Schemes
|
|
70
72
|
|
|
73
|
+
#
|
|
74
|
+
# Register the given +klass+ to be instantiated when parsing URLs with the given +scheme+.
|
|
75
|
+
# Note that currently only schemes which after .upcase are valid constant names
|
|
76
|
+
# can be registered (no -/+/. allowed).
|
|
77
|
+
#
|
|
71
78
|
def self.register_scheme(scheme, klass)
|
|
72
|
-
Schemes.const_set(scheme, klass)
|
|
79
|
+
Schemes.const_set(scheme.to_s.upcase, klass)
|
|
73
80
|
end
|
|
74
81
|
|
|
75
82
|
# Returns a Hash of the defined schemes.
|
|
@@ -295,6 +302,7 @@ module URI
|
|
|
295
302
|
256.times do |i|
|
|
296
303
|
TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i)
|
|
297
304
|
end
|
|
305
|
+
TBLENCURICOMP_ = TBLENCWWWCOMP_.dup.freeze
|
|
298
306
|
TBLENCWWWCOMP_[' '] = '+'
|
|
299
307
|
TBLENCWWWCOMP_.freeze
|
|
300
308
|
TBLDECWWWCOMP_ = {} # :nodoc:
|
|
@@ -320,6 +328,33 @@ module URI
|
|
|
320
328
|
#
|
|
321
329
|
# See URI.decode_www_form_component, URI.encode_www_form.
|
|
322
330
|
def self.encode_www_form_component(str, enc=nil)
|
|
331
|
+
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Decodes given +str+ of URL-encoded form data.
|
|
335
|
+
#
|
|
336
|
+
# This decodes + to SP.
|
|
337
|
+
#
|
|
338
|
+
# See URI.encode_www_form_component, URI.decode_www_form.
|
|
339
|
+
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
|
340
|
+
_decode_uri_component(/\+|%\h\h/, str, enc)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
# Encodes +str+ using URL encoding
|
|
344
|
+
#
|
|
345
|
+
# This encodes SP to %20 instead of +.
|
|
346
|
+
def self.encode_uri_component(str, enc=nil)
|
|
347
|
+
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCURICOMP_, str, enc)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# Decodes given +str+ of URL-encoded data.
|
|
351
|
+
#
|
|
352
|
+
# This does not decode + to SP.
|
|
353
|
+
def self.decode_uri_component(str, enc=Encoding::UTF_8)
|
|
354
|
+
_decode_uri_component(/%\h\h/, str, enc)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def self._encode_uri_component(regexp, table, str, enc)
|
|
323
358
|
str = str.to_s.dup
|
|
324
359
|
if str.encoding != Encoding::ASCII_8BIT
|
|
325
360
|
if enc && enc != Encoding::ASCII_8BIT
|
|
@@ -328,19 +363,16 @@ module URI
|
|
|
328
363
|
end
|
|
329
364
|
str.force_encoding(Encoding::ASCII_8BIT)
|
|
330
365
|
end
|
|
331
|
-
str.gsub!(
|
|
366
|
+
str.gsub!(regexp, table)
|
|
332
367
|
str.force_encoding(Encoding::US_ASCII)
|
|
333
368
|
end
|
|
369
|
+
private_class_method :_encode_uri_component
|
|
334
370
|
|
|
335
|
-
|
|
336
|
-
#
|
|
337
|
-
# This decodes + to SP.
|
|
338
|
-
#
|
|
339
|
-
# See URI.encode_www_form_component, URI.decode_www_form.
|
|
340
|
-
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
|
371
|
+
def self._decode_uri_component(regexp, str, enc)
|
|
341
372
|
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/.match?(str)
|
|
342
|
-
str.b.gsub(
|
|
373
|
+
str.b.gsub(regexp, TBLDECWWWCOMP_).force_encoding(enc)
|
|
343
374
|
end
|
|
375
|
+
private_class_method :_decode_uri_component
|
|
344
376
|
|
|
345
377
|
# Generates URL-encoded form data from given +enum+.
|
|
346
378
|
#
|
data/lib/uri/file.rb
CHANGED
|
@@ -33,6 +33,9 @@ module URI
|
|
|
33
33
|
# If an Array is used, the components must be passed in the
|
|
34
34
|
# order <code>[host, path]</code>.
|
|
35
35
|
#
|
|
36
|
+
# A path from e.g. the File class should be escaped before
|
|
37
|
+
# being passed.
|
|
38
|
+
#
|
|
36
39
|
# Examples:
|
|
37
40
|
#
|
|
38
41
|
# require 'uri'
|
|
@@ -44,6 +47,9 @@ module URI
|
|
|
44
47
|
# :path => '/ruby/src'})
|
|
45
48
|
# uri2.to_s # => "file://host.example.com/ruby/src"
|
|
46
49
|
#
|
|
50
|
+
# uri3 = URI::File.build({:path => URI::escape('/path/my file.txt')})
|
|
51
|
+
# uri3.to_s # => "file:///path/my%20file.txt"
|
|
52
|
+
#
|
|
47
53
|
def self.build(args)
|
|
48
54
|
tmp = Util::make_components_hash(self, args)
|
|
49
55
|
super(tmp)
|
data/lib/uri/generic.rb
CHANGED
|
@@ -186,18 +186,18 @@ module URI
|
|
|
186
186
|
|
|
187
187
|
if arg_check
|
|
188
188
|
self.scheme = scheme
|
|
189
|
-
self.userinfo = userinfo
|
|
190
189
|
self.hostname = host
|
|
191
190
|
self.port = port
|
|
191
|
+
self.userinfo = userinfo
|
|
192
192
|
self.path = path
|
|
193
193
|
self.query = query
|
|
194
194
|
self.opaque = opaque
|
|
195
195
|
self.fragment = fragment
|
|
196
196
|
else
|
|
197
197
|
self.set_scheme(scheme)
|
|
198
|
-
self.set_userinfo(userinfo)
|
|
199
198
|
self.set_host(host)
|
|
200
199
|
self.set_port(port)
|
|
200
|
+
self.set_userinfo(userinfo)
|
|
201
201
|
self.set_path(path)
|
|
202
202
|
self.query = query
|
|
203
203
|
self.set_opaque(opaque)
|
|
@@ -511,7 +511,7 @@ module URI
|
|
|
511
511
|
user, password = split_userinfo(user)
|
|
512
512
|
end
|
|
513
513
|
@user = user
|
|
514
|
-
@password = password
|
|
514
|
+
@password = password
|
|
515
515
|
|
|
516
516
|
[@user, @password]
|
|
517
517
|
end
|
|
@@ -522,7 +522,7 @@ module URI
|
|
|
522
522
|
# See also URI::Generic.user=.
|
|
523
523
|
#
|
|
524
524
|
def set_user(v)
|
|
525
|
-
set_userinfo(v,
|
|
525
|
+
set_userinfo(v, nil)
|
|
526
526
|
v
|
|
527
527
|
end
|
|
528
528
|
protected :set_user
|
|
@@ -564,16 +564,32 @@ module URI
|
|
|
564
564
|
end
|
|
565
565
|
end
|
|
566
566
|
|
|
567
|
-
# Returns the user component.
|
|
567
|
+
# Returns the user component (without URI decoding).
|
|
568
568
|
def user
|
|
569
569
|
@user
|
|
570
570
|
end
|
|
571
571
|
|
|
572
|
-
# Returns the password component.
|
|
572
|
+
# Returns the password component (without URI decoding).
|
|
573
573
|
def password
|
|
574
574
|
@password
|
|
575
575
|
end
|
|
576
576
|
|
|
577
|
+
# Returns the authority info (array of user, password, host and
|
|
578
|
+
# port), if any is set. Or returns +nil+.
|
|
579
|
+
def authority
|
|
580
|
+
return @user, @password, @host, @port if @user || @password || @host || @port
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
# Returns the user component after URI decoding.
|
|
584
|
+
def decoded_user
|
|
585
|
+
URI.decode_uri_component(@user) if @user
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
# Returns the password component after URI decoding.
|
|
589
|
+
def decoded_password
|
|
590
|
+
URI.decode_uri_component(@password) if @password
|
|
591
|
+
end
|
|
592
|
+
|
|
577
593
|
#
|
|
578
594
|
# Checks the host +v+ component for RFC2396 compliance
|
|
579
595
|
# and against the URI::Parser Regexp for :HOST.
|
|
@@ -605,6 +621,13 @@ module URI
|
|
|
605
621
|
end
|
|
606
622
|
protected :set_host
|
|
607
623
|
|
|
624
|
+
# Protected setter for the authority info (+user+, +password+, +host+
|
|
625
|
+
# and +port+). If +port+ is +nil+, +default_port+ will be set.
|
|
626
|
+
#
|
|
627
|
+
protected def set_authority(user, password, host, port = nil)
|
|
628
|
+
@user, @password, @host, @port = user, password, host, port || self.default_port
|
|
629
|
+
end
|
|
630
|
+
|
|
608
631
|
#
|
|
609
632
|
# == Args
|
|
610
633
|
#
|
|
@@ -629,6 +652,7 @@ module URI
|
|
|
629
652
|
def host=(v)
|
|
630
653
|
check_host(v)
|
|
631
654
|
set_host(v)
|
|
655
|
+
set_userinfo(nil)
|
|
632
656
|
v
|
|
633
657
|
end
|
|
634
658
|
|
|
@@ -719,6 +743,7 @@ module URI
|
|
|
719
743
|
def port=(v)
|
|
720
744
|
check_port(v)
|
|
721
745
|
set_port(v)
|
|
746
|
+
set_userinfo(nil)
|
|
722
747
|
port
|
|
723
748
|
end
|
|
724
749
|
|
|
@@ -1111,7 +1136,7 @@ module URI
|
|
|
1111
1136
|
|
|
1112
1137
|
base = self.dup
|
|
1113
1138
|
|
|
1114
|
-
authority = rel.
|
|
1139
|
+
authority = rel.authority
|
|
1115
1140
|
|
|
1116
1141
|
# RFC2396, Section 5.2, 2)
|
|
1117
1142
|
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
|
|
@@ -1124,9 +1149,7 @@ module URI
|
|
|
1124
1149
|
|
|
1125
1150
|
# RFC2396, Section 5.2, 4)
|
|
1126
1151
|
if authority
|
|
1127
|
-
base.
|
|
1128
|
-
base.set_host(rel.host)
|
|
1129
|
-
base.set_port(rel.port || base.default_port)
|
|
1152
|
+
base.set_authority(*authority)
|
|
1130
1153
|
base.set_path(rel.path)
|
|
1131
1154
|
elsif base.path && rel.path
|
|
1132
1155
|
base.set_path(merge_path(base.path, rel.path))
|
data/lib/uri/mailto.rb
CHANGED
data/lib/uri/rfc3986_parser.rb
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
module URI
|
|
3
3
|
class RFC3986_Parser # :nodoc:
|
|
4
4
|
# URI defined in RFC3986
|
|
5
|
-
|
|
6
|
-
RFC3986_URI = /\A(?<URI>(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*+):(?<hier-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*+)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h++\.[!$&-.0-;=A-Z_a-z~]++))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])++))?(?::(?<port>\d*+))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*+))*+)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])++)(?:\/\g<segment>)*+)?)|(?<path-rootless>\g<segment-nz>(?:\/\g<segment>)*+)|(?<path-empty>))(?:\?(?<query>[^#]*+))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*+))?)\z/
|
|
5
|
+
RFC3986_URI = /\A(?<URI>(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*+):(?<hier-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*+)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h++\.[!$&-.0-;=A-Z_a-z~]++))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+))(?::(?<port>\d*+))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*+))*+)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])++)(?:\/\g<segment>)*+)?)|(?<path-rootless>\g<segment-nz>(?:\/\g<segment>)*+)|(?<path-empty>))(?:\?(?<query>[^#]*+))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*+))?)\z/
|
|
7
6
|
RFC3986_relative_ref = /\A(?<relative-ref>(?<relative-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*+)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:){,1}\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h++\.[!$&-.0-;=A-Z_a-z~]++))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])++))?(?::(?<port>\d*+))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*+))*+)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])++)(?:\/\g<segment>)*+)?)|(?<path-noscheme>(?<segment-nz-nc>(?:%\h\h|[!$&-.0-9;=@-Z_a-z~])++)(?:\/\g<segment>)*+)|(?<path-empty>))(?:\?(?<query>[^#]*+))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*+))?)\z/
|
|
8
7
|
attr_reader :regexp
|
|
9
8
|
|
data/lib/uri/version.rb
CHANGED
data/lib/uri.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.12.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Akira Yamada
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: URI is a module providing classes to handle Uniform Resource Identifiers
|
|
14
13
|
email:
|
|
@@ -17,6 +16,7 @@ executables: []
|
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
19
18
|
files:
|
|
19
|
+
- ".github/dependabot.yml"
|
|
20
20
|
- ".github/workflows/test.yml"
|
|
21
21
|
- ".gitignore"
|
|
22
22
|
- Gemfile
|
|
@@ -48,7 +48,6 @@ licenses:
|
|
|
48
48
|
metadata:
|
|
49
49
|
homepage_uri: https://github.com/ruby/uri
|
|
50
50
|
source_code_uri: https://github.com/ruby/uri
|
|
51
|
-
post_install_message:
|
|
52
51
|
rdoc_options: []
|
|
53
52
|
require_paths:
|
|
54
53
|
- lib
|
|
@@ -63,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
63
62
|
- !ruby/object:Gem::Version
|
|
64
63
|
version: '0'
|
|
65
64
|
requirements: []
|
|
66
|
-
rubygems_version: 3.
|
|
67
|
-
signing_key:
|
|
65
|
+
rubygems_version: 3.8.0.dev
|
|
68
66
|
specification_version: 4
|
|
69
67
|
summary: URI is a module providing classes to handle Uniform Resource Identifiers
|
|
70
68
|
test_files: []
|