uri 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of uri might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/uri.rb +104 -0
- data/lib/uri/common.rb +744 -0
- data/lib/uri/file.rb +94 -0
- data/lib/uri/ftp.rb +267 -0
- data/lib/uri/generic.rb +1568 -0
- data/lib/uri/http.rb +88 -0
- data/lib/uri/https.rb +23 -0
- data/lib/uri/ldap.rb +261 -0
- data/lib/uri/ldaps.rb +21 -0
- data/lib/uri/mailto.rb +294 -0
- data/lib/uri/rfc2396_parser.rb +546 -0
- data/lib/uri/rfc3986_parser.rb +125 -0
- data/lib/uri/version.rb +6 -0
- data/uri.gemspec +29 -0
- metadata +67 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
module URI
|
3
|
+
class RFC3986_Parser # :nodoc:
|
4
|
+
# URI defined in RFC3986
|
5
|
+
# this regexp is modified not to host is not empty string
|
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/
|
7
|
+
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
|
+
attr_reader :regexp
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@regexp = default_regexp.each_value(&:freeze).freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def split(uri) #:nodoc:
|
15
|
+
begin
|
16
|
+
uri = uri.to_str
|
17
|
+
rescue NoMethodError
|
18
|
+
raise InvalidURIError, "bad URI(is not URI?): #{uri.inspect}"
|
19
|
+
end
|
20
|
+
uri.ascii_only? or
|
21
|
+
raise InvalidURIError, "URI must be ascii only #{uri.dump}"
|
22
|
+
if m = RFC3986_URI.match(uri)
|
23
|
+
query = m["query".freeze]
|
24
|
+
scheme = m["scheme".freeze]
|
25
|
+
opaque = m["path-rootless".freeze]
|
26
|
+
if opaque
|
27
|
+
opaque << "?#{query}" if query
|
28
|
+
[ scheme,
|
29
|
+
nil, # userinfo
|
30
|
+
nil, # host
|
31
|
+
nil, # port
|
32
|
+
nil, # registry
|
33
|
+
nil, # path
|
34
|
+
opaque,
|
35
|
+
nil, # query
|
36
|
+
m["fragment".freeze]
|
37
|
+
]
|
38
|
+
else # normal
|
39
|
+
[ scheme,
|
40
|
+
m["userinfo".freeze],
|
41
|
+
m["host".freeze],
|
42
|
+
m["port".freeze],
|
43
|
+
nil, # registry
|
44
|
+
(m["path-abempty".freeze] ||
|
45
|
+
m["path-absolute".freeze] ||
|
46
|
+
m["path-empty".freeze]),
|
47
|
+
nil, # opaque
|
48
|
+
query,
|
49
|
+
m["fragment".freeze]
|
50
|
+
]
|
51
|
+
end
|
52
|
+
elsif m = RFC3986_relative_ref.match(uri)
|
53
|
+
[ nil, # scheme
|
54
|
+
m["userinfo".freeze],
|
55
|
+
m["host".freeze],
|
56
|
+
m["port".freeze],
|
57
|
+
nil, # registry,
|
58
|
+
(m["path-abempty".freeze] ||
|
59
|
+
m["path-absolute".freeze] ||
|
60
|
+
m["path-noscheme".freeze] ||
|
61
|
+
m["path-empty".freeze]),
|
62
|
+
nil, # opaque
|
63
|
+
m["query".freeze],
|
64
|
+
m["fragment".freeze]
|
65
|
+
]
|
66
|
+
else
|
67
|
+
raise InvalidURIError, "bad URI(is not URI?): #{uri.inspect}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse(uri) # :nodoc:
|
72
|
+
scheme, userinfo, host, port,
|
73
|
+
registry, path, opaque, query, fragment = self.split(uri)
|
74
|
+
scheme_list = URI.scheme_list
|
75
|
+
if scheme && scheme_list.include?(uc = scheme.upcase)
|
76
|
+
scheme_list[uc].new(scheme, userinfo, host, port,
|
77
|
+
registry, path, opaque, query,
|
78
|
+
fragment, self)
|
79
|
+
else
|
80
|
+
Generic.new(scheme, userinfo, host, port,
|
81
|
+
registry, path, opaque, query,
|
82
|
+
fragment, self)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def join(*uris) # :nodoc:
|
88
|
+
uris[0] = convert_to_uri(uris[0])
|
89
|
+
uris.inject :merge
|
90
|
+
end
|
91
|
+
|
92
|
+
@@to_s = Kernel.instance_method(:to_s)
|
93
|
+
def inspect
|
94
|
+
@@to_s.bind_call(self)
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def default_regexp # :nodoc:
|
100
|
+
{
|
101
|
+
SCHEME: /\A[A-Za-z][A-Za-z0-9+\-.]*\z/,
|
102
|
+
USERINFO: /\A(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*\z/,
|
103
|
+
HOST: /\A(?:(?<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{,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~])*))\z/,
|
104
|
+
ABS_PATH: /\A\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/,
|
105
|
+
REL_PATH: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/,
|
106
|
+
QUERY: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
107
|
+
FRAGMENT: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
108
|
+
OPAQUE: /\A(?:[^\/].*)?\z/,
|
109
|
+
PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/,
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def convert_to_uri(uri)
|
114
|
+
if uri.is_a?(URI::Generic)
|
115
|
+
uri
|
116
|
+
elsif uri = String.try_convert(uri)
|
117
|
+
parse(uri)
|
118
|
+
else
|
119
|
+
raise ArgumentError,
|
120
|
+
"bad argument (expected URI object or URI string)"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end # class Parser
|
125
|
+
end # module URI
|
data/lib/uri/version.rb
ADDED
data/uri.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require_relative "lib/uri/version"
|
3
|
+
rescue LoadError # Fallback to load version file in ruby core repository
|
4
|
+
require_relative "version"
|
5
|
+
end
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "uri"
|
9
|
+
spec.version = URI::VERSION
|
10
|
+
spec.authors = ["Akira Yamada"]
|
11
|
+
spec.email = ["akira@ruby-lang.org"]
|
12
|
+
|
13
|
+
spec.summary = %q{URI is a module providing classes to handle Uniform Resource Identifiers}
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = "https://github.com/ruby/uri"
|
16
|
+
spec.license = "BSD-2-Clause"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Yamada
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: URI is a module providing classes to handle Uniform Resource Identifiers
|
14
|
+
email:
|
15
|
+
- akira@ruby-lang.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/uri.rb
|
29
|
+
- lib/uri/common.rb
|
30
|
+
- lib/uri/file.rb
|
31
|
+
- lib/uri/ftp.rb
|
32
|
+
- lib/uri/generic.rb
|
33
|
+
- lib/uri/http.rb
|
34
|
+
- lib/uri/https.rb
|
35
|
+
- lib/uri/ldap.rb
|
36
|
+
- lib/uri/ldaps.rb
|
37
|
+
- lib/uri/mailto.rb
|
38
|
+
- lib/uri/rfc2396_parser.rb
|
39
|
+
- lib/uri/rfc3986_parser.rb
|
40
|
+
- lib/uri/version.rb
|
41
|
+
- uri.gemspec
|
42
|
+
homepage: https://github.com/ruby/uri
|
43
|
+
licenses:
|
44
|
+
- BSD-2-Clause
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://github.com/ruby/uri
|
47
|
+
source_code_uri: https://github.com/ruby/uri
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.2.0.pre1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: URI is a module providing classes to handle Uniform Resource Identifiers
|
67
|
+
test_files: []
|