rubygems-update 3.5.5 → 3.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -0
  3. data/Manifest.txt +84 -64
  4. data/POLICIES.md +75 -6
  5. data/bundler/CHANGELOG.md +75 -0
  6. data/bundler/lib/bundler/build_metadata.rb +2 -2
  7. data/bundler/lib/bundler/cli/binstubs.rb +1 -1
  8. data/bundler/lib/bundler/cli/gem.rb +1 -1
  9. data/bundler/lib/bundler/cli/lock.rb +5 -4
  10. data/bundler/lib/bundler/cli/plugin.rb +3 -2
  11. data/bundler/lib/bundler/cli.rb +7 -24
  12. data/bundler/lib/bundler/definition.rb +111 -56
  13. data/bundler/lib/bundler/dependency.rb +2 -1
  14. data/bundler/lib/bundler/dsl.rb +16 -1
  15. data/bundler/lib/bundler/environment_preserver.rb +5 -23
  16. data/bundler/lib/bundler/fetcher/downloader.rb +1 -1
  17. data/bundler/lib/bundler/fetcher.rb +2 -2
  18. data/bundler/lib/bundler/gem_version_promoter.rb +42 -38
  19. data/bundler/lib/bundler/injector.rb +3 -2
  20. data/bundler/lib/bundler/installer.rb +2 -2
  21. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  22. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  23. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  24. data/bundler/lib/bundler/man/bundle-check.1 +3 -1
  25. data/bundler/lib/bundler/man/bundle-check.1.ronn +3 -0
  26. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  27. data/bundler/lib/bundler/man/bundle-config.1 +1 -3
  28. data/bundler/lib/bundler/man/bundle-config.1.ronn +0 -3
  29. data/bundler/lib/bundler/man/bundle-console.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
  33. data/bundler/lib/bundler/man/bundle-help.1 +1 -1
  34. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  36. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  37. data/bundler/lib/bundler/man/bundle-install.1 +3 -3
  38. data/bundler/lib/bundler/man/bundle-install.1.ronn +2 -2
  39. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  40. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  41. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  42. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  43. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  44. data/bundler/lib/bundler/man/bundle-plugin.1 +7 -4
  45. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +7 -3
  46. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  47. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  48. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  49. data/bundler/lib/bundler/man/bundle-update.1 +1 -1
  50. data/bundler/lib/bundler/man/bundle-version.1 +1 -1
  51. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  52. data/bundler/lib/bundler/man/bundle.1 +1 -1
  53. data/bundler/lib/bundler/man/gemfile.5 +3 -3
  54. data/bundler/lib/bundler/man/gemfile.5.ronn +2 -2
  55. data/bundler/lib/bundler/mirror.rb +3 -3
  56. data/bundler/lib/bundler/plugin/api/source.rb +2 -2
  57. data/bundler/lib/bundler/plugin/installer/path.rb +18 -0
  58. data/bundler/lib/bundler/plugin/installer.rb +36 -16
  59. data/bundler/lib/bundler/plugin/source_list.rb +4 -4
  60. data/bundler/lib/bundler/resolver/candidate.rb +1 -1
  61. data/bundler/lib/bundler/resolver.rb +54 -24
  62. data/bundler/lib/bundler/rubygems_ext.rb +12 -0
  63. data/bundler/lib/bundler/runtime.rb +1 -1
  64. data/bundler/lib/bundler/self_manager.rb +1 -1
  65. data/bundler/lib/bundler/settings.rb +14 -12
  66. data/bundler/lib/bundler/setup.rb +3 -0
  67. data/bundler/lib/bundler/source/git/git_proxy.rb +1 -1
  68. data/bundler/lib/bundler/source/git.rb +1 -1
  69. data/bundler/lib/bundler/source/rubygems/remote.rb +1 -1
  70. data/bundler/lib/bundler/source/rubygems.rb +7 -20
  71. data/bundler/lib/bundler/source_list.rb +17 -4
  72. data/bundler/lib/bundler/spec_set.rb +1 -1
  73. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +4 -3
  74. data/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +0 -5
  75. data/bundler/lib/bundler/uri_credentials_filter.rb +2 -2
  76. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +22 -22
  77. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +1 -0
  78. data/bundler/lib/bundler/vendored_net_http.rb +7 -3
  79. data/bundler/lib/bundler/vendored_timeout.rb +7 -3
  80. data/bundler/lib/bundler/vendored_uri.rb +18 -1
  81. data/bundler/lib/bundler/version.rb +1 -1
  82. data/bundler/lib/bundler/yaml_serializer.rb +12 -0
  83. data/bundler/lib/bundler.rb +23 -2
  84. data/lib/rubygems/command.rb +1 -1
  85. data/lib/rubygems/command_manager.rb +2 -1
  86. data/lib/rubygems/commands/build_command.rb +2 -11
  87. data/lib/rubygems/commands/help_command.rb +2 -2
  88. data/lib/rubygems/commands/rdoc_command.rb +1 -8
  89. data/lib/rubygems/commands/rebuild_command.rb +264 -0
  90. data/lib/rubygems/commands/sources_command.rb +2 -2
  91. data/lib/rubygems/commands/update_command.rb +8 -9
  92. data/lib/rubygems/config_file.rb +20 -8
  93. data/lib/rubygems/defaults.rb +4 -4
  94. data/lib/rubygems/dependency.rb +2 -2
  95. data/lib/rubygems/dependency_list.rb +1 -1
  96. data/lib/rubygems/deprecate.rb +79 -77
  97. data/lib/rubygems/ext/cargo_builder.rb +1 -1
  98. data/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +1 -1
  99. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +3 -1
  100. data/lib/rubygems/gemcutter_utilities.rb +40 -23
  101. data/lib/rubygems/gemspec_helpers.rb +19 -0
  102. data/lib/rubygems/local_remote_options.rb +6 -6
  103. data/lib/rubygems/package.rb +13 -7
  104. data/lib/rubygems/remote_fetcher.rb +3 -3
  105. data/lib/rubygems/request.rb +5 -5
  106. data/lib/rubygems/request_set.rb +1 -1
  107. data/lib/rubygems/requirement.rb +5 -0
  108. data/lib/rubygems/resolver/api_set.rb +1 -1
  109. data/lib/rubygems/resolver/best_set.rb +1 -1
  110. data/lib/rubygems/resolver/spec_specification.rb +7 -0
  111. data/lib/rubygems/resolver.rb +5 -5
  112. data/lib/rubygems/s3_uri_signer.rb +3 -3
  113. data/lib/rubygems/safe_yaml.rb +10 -1
  114. data/lib/rubygems/security.rb +1 -1
  115. data/lib/rubygems/source/git.rb +2 -2
  116. data/lib/rubygems/source_list.rb +1 -1
  117. data/lib/rubygems/specification.rb +6 -6
  118. data/lib/rubygems/specification_policy.rb +15 -7
  119. data/lib/rubygems/uri.rb +6 -6
  120. data/lib/rubygems/util/licenses.rb +43 -0
  121. data/lib/rubygems/util.rb +1 -1
  122. data/lib/rubygems/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  123. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/delegates/specification_provider.rb +11 -11
  124. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/action.rb +1 -1
  125. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  126. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  127. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  128. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  129. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/log.rb +1 -1
  130. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  131. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  132. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/vertex.rb +1 -1
  133. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  134. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/errors.rb +1 -1
  135. data/lib/rubygems/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
  136. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/specification_provider.rb +2 -2
  137. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/ui.rb +1 -1
  138. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolution.rb +3 -3
  139. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolver.rb +1 -1
  140. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/state.rb +1 -1
  141. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo.rb +2 -2
  142. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/generic_request.rb +9 -9
  143. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/header.rb +2 -2
  144. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/request.rb +3 -3
  145. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/requests.rb +30 -30
  146. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/response.rb +2 -2
  147. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/responses.rb +6 -6
  148. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/status.rb +1 -1
  149. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http.rb +15 -15
  150. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/https.rb +1 -1
  151. data/lib/rubygems/vendor/optparse/lib/optparse/uri.rb +7 -0
  152. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse.rb +11 -11
  153. data/lib/rubygems/{timeout → vendor/timeout}/lib/timeout.rb +1 -1
  154. data/lib/rubygems/{tsort → vendor/tsort}/lib/tsort.rb +2 -2
  155. data/lib/rubygems/vendor/uri/.document +1 -0
  156. data/lib/rubygems/vendor/uri/LICENSE.txt +22 -0
  157. data/lib/rubygems/vendor/uri/lib/uri/common.rb +853 -0
  158. data/lib/rubygems/vendor/uri/lib/uri/file.rb +100 -0
  159. data/lib/rubygems/vendor/uri/lib/uri/ftp.rb +267 -0
  160. data/lib/rubygems/vendor/uri/lib/uri/generic.rb +1588 -0
  161. data/lib/rubygems/vendor/uri/lib/uri/http.rb +125 -0
  162. data/lib/rubygems/vendor/uri/lib/uri/https.rb +23 -0
  163. data/lib/rubygems/vendor/uri/lib/uri/ldap.rb +261 -0
  164. data/lib/rubygems/vendor/uri/lib/uri/ldaps.rb +22 -0
  165. data/lib/rubygems/vendor/uri/lib/uri/mailto.rb +293 -0
  166. data/lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb +539 -0
  167. data/lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb +183 -0
  168. data/lib/rubygems/vendor/uri/lib/uri/version.rb +6 -0
  169. data/lib/rubygems/vendor/uri/lib/uri/ws.rb +83 -0
  170. data/lib/rubygems/vendor/uri/lib/uri/wss.rb +23 -0
  171. data/lib/rubygems/vendor/uri/lib/uri.rb +104 -0
  172. data/lib/rubygems/vendored_molinillo.rb +3 -0
  173. data/lib/rubygems/vendored_net_http.rb +5 -0
  174. data/lib/rubygems/vendored_optparse.rb +3 -0
  175. data/lib/rubygems/vendored_timeout.rb +5 -0
  176. data/lib/rubygems/vendored_tsort.rb +3 -0
  177. data/lib/rubygems/yaml_serializer.rb +12 -0
  178. data/lib/rubygems.rb +2 -2
  179. data/rubygems-update.gemspec +7 -2
  180. metadata +90 -67
  181. data/lib/rubygems/net/http.rb +0 -3
  182. data/lib/rubygems/optparse/lib/optparse/uri.rb +0 -7
  183. data/lib/rubygems/optparse.rb +0 -3
  184. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  185. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  186. data/lib/rubygems/resolver/molinillo.rb +0 -3
  187. data/lib/rubygems/timeout.rb +0 -3
  188. data/lib/rubygems/tsort.rb +0 -3
  189. /data/lib/rubygems/{net-http → vendor/molinillo}/.document +0 -0
  190. /data/lib/rubygems/{resolver → vendor}/molinillo/LICENSE +0 -0
  191. /data/lib/rubygems/{net-protocol → vendor/net-http}/.document +0 -0
  192. /data/lib/rubygems/{net-http → vendor/net-http}/LICENSE.txt +0 -0
  193. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/backward.rb +0 -0
  194. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/exceptions.rb +0 -0
  195. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/proxy_delta.rb +0 -0
  196. /data/lib/rubygems/{optparse → vendor/net-protocol}/.document +0 -0
  197. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/LICENSE.txt +0 -0
  198. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/lib/net/protocol.rb +0 -0
  199. /data/lib/rubygems/{resolv → vendor/optparse}/.document +0 -0
  200. /data/lib/rubygems/{optparse → vendor/optparse}/COPYING +0 -0
  201. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optionparser.rb +0 -0
  202. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/ac.rb +0 -0
  203. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/date.rb +0 -0
  204. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/kwargs.rb +0 -0
  205. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/shellwords.rb +0 -0
  206. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/time.rb +0 -0
  207. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/version.rb +0 -0
  208. /data/lib/rubygems/{resolver/molinillo → vendor/resolv}/.document +0 -0
  209. /data/lib/rubygems/{resolv → vendor/resolv}/LICENSE.txt +0 -0
  210. /data/lib/rubygems/{resolv → vendor/resolv}/lib/resolv.rb +0 -0
  211. /data/lib/rubygems/{timeout → vendor/timeout}/.document +0 -0
  212. /data/lib/rubygems/{timeout → vendor/timeout}/LICENSE.txt +0 -0
  213. /data/lib/rubygems/{tsort → vendor/tsort}/.document +0 -0
  214. /data/lib/rubygems/{tsort → vendor/tsort}/LICENSE.txt +0 -0
@@ -0,0 +1,539 @@
1
+ # frozen_string_literal: false
2
+ #--
3
+ # = uri/common.rb
4
+ #
5
+ # Author:: Akira Yamada <akira@ruby-lang.org>
6
+ # License::
7
+ # You can redistribute it and/or modify it under the same term as Ruby.
8
+ #
9
+ # See Gem::URI for general documentation
10
+ #
11
+
12
+ module Gem::URI
13
+ #
14
+ # Includes Gem::URI::REGEXP::PATTERN
15
+ #
16
+ module RFC2396_REGEXP
17
+ #
18
+ # Patterns used to parse Gem::URI's
19
+ #
20
+ module PATTERN
21
+ # :stopdoc:
22
+
23
+ # RFC 2396 (Gem::URI Generic Syntax)
24
+ # RFC 2732 (IPv6 Literal Addresses in URL's)
25
+ # RFC 2373 (IPv6 Addressing Architecture)
26
+
27
+ # alpha = lowalpha | upalpha
28
+ ALPHA = "a-zA-Z"
29
+ # alphanum = alpha | digit
30
+ ALNUM = "#{ALPHA}\\d"
31
+
32
+ # hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
33
+ # "a" | "b" | "c" | "d" | "e" | "f"
34
+ HEX = "a-fA-F\\d"
35
+ # escaped = "%" hex hex
36
+ ESCAPED = "%[#{HEX}]{2}"
37
+ # mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
38
+ # "(" | ")"
39
+ # unreserved = alphanum | mark
40
+ UNRESERVED = "\\-_.!~*'()#{ALNUM}"
41
+ # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
42
+ # "$" | ","
43
+ # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
44
+ # "$" | "," | "[" | "]" (RFC 2732)
45
+ RESERVED = ";/?:@&=+$,\\[\\]"
46
+
47
+ # domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
48
+ DOMLABEL = "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
49
+ # toplabel = alpha | alpha *( alphanum | "-" ) alphanum
50
+ TOPLABEL = "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
51
+ # hostname = *( domainlabel "." ) toplabel [ "." ]
52
+ HOSTNAME = "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?"
53
+
54
+ # :startdoc:
55
+ end # PATTERN
56
+
57
+ # :startdoc:
58
+ end # REGEXP
59
+
60
+ # Class that parses String's into Gem::URI's.
61
+ #
62
+ # It contains a Hash set of patterns and Regexp's that match and validate.
63
+ #
64
+ class RFC2396_Parser
65
+ include RFC2396_REGEXP
66
+
67
+ #
68
+ # == Synopsis
69
+ #
70
+ # Gem::URI::Parser.new([opts])
71
+ #
72
+ # == Args
73
+ #
74
+ # The constructor accepts a hash as options for parser.
75
+ # Keys of options are pattern names of Gem::URI components
76
+ # and values of options are pattern strings.
77
+ # The constructor generates set of regexps for parsing URIs.
78
+ #
79
+ # You can use the following keys:
80
+ #
81
+ # * :ESCAPED (Gem::URI::PATTERN::ESCAPED in default)
82
+ # * :UNRESERVED (Gem::URI::PATTERN::UNRESERVED in default)
83
+ # * :DOMLABEL (Gem::URI::PATTERN::DOMLABEL in default)
84
+ # * :TOPLABEL (Gem::URI::PATTERN::TOPLABEL in default)
85
+ # * :HOSTNAME (Gem::URI::PATTERN::HOSTNAME in default)
86
+ #
87
+ # == Examples
88
+ #
89
+ # p = Gem::URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
90
+ # u = p.parse("http://example.jp/%uABCD") #=> #<Gem::URI::HTTP http://example.jp/%uABCD>
91
+ # Gem::URI.parse(u.to_s) #=> raises Gem::URI::InvalidURIError
92
+ #
93
+ # s = "http://example.com/ABCD"
94
+ # u1 = p.parse(s) #=> #<Gem::URI::HTTP http://example.com/ABCD>
95
+ # u2 = Gem::URI.parse(s) #=> #<Gem::URI::HTTP http://example.com/ABCD>
96
+ # u1 == u2 #=> true
97
+ # u1.eql?(u2) #=> false
98
+ #
99
+ def initialize(opts = {})
100
+ @pattern = initialize_pattern(opts)
101
+ @pattern.each_value(&:freeze)
102
+ @pattern.freeze
103
+
104
+ @regexp = initialize_regexp(@pattern)
105
+ @regexp.each_value(&:freeze)
106
+ @regexp.freeze
107
+ end
108
+
109
+ # The Hash of patterns.
110
+ #
111
+ # See also Gem::URI::Parser.initialize_pattern.
112
+ attr_reader :pattern
113
+
114
+ # The Hash of Regexp.
115
+ #
116
+ # See also Gem::URI::Parser.initialize_regexp.
117
+ attr_reader :regexp
118
+
119
+ # Returns a split Gem::URI against +regexp[:ABS_URI]+.
120
+ def split(uri)
121
+ case uri
122
+ when ''
123
+ # null uri
124
+
125
+ when @regexp[:ABS_URI]
126
+ scheme, opaque, userinfo, host, port,
127
+ registry, path, query, fragment = $~[1..-1]
128
+
129
+ # Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
130
+
131
+ # absoluteURI = scheme ":" ( hier_part | opaque_part )
132
+ # hier_part = ( net_path | abs_path ) [ "?" query ]
133
+ # opaque_part = uric_no_slash *uric
134
+
135
+ # abs_path = "/" path_segments
136
+ # net_path = "//" authority [ abs_path ]
137
+
138
+ # authority = server | reg_name
139
+ # server = [ [ userinfo "@" ] hostport ]
140
+
141
+ if !scheme
142
+ raise InvalidURIError,
143
+ "bad Gem::URI(absolute but no scheme): #{uri}"
144
+ end
145
+ if !opaque && (!path && (!host && !registry))
146
+ raise InvalidURIError,
147
+ "bad Gem::URI(absolute but no path): #{uri}"
148
+ end
149
+
150
+ when @regexp[:REL_URI]
151
+ scheme = nil
152
+ opaque = nil
153
+
154
+ userinfo, host, port, registry,
155
+ rel_segment, abs_path, query, fragment = $~[1..-1]
156
+ if rel_segment && abs_path
157
+ path = rel_segment + abs_path
158
+ elsif rel_segment
159
+ path = rel_segment
160
+ elsif abs_path
161
+ path = abs_path
162
+ end
163
+
164
+ # Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
165
+
166
+ # relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
167
+
168
+ # net_path = "//" authority [ abs_path ]
169
+ # abs_path = "/" path_segments
170
+ # rel_path = rel_segment [ abs_path ]
171
+
172
+ # authority = server | reg_name
173
+ # server = [ [ userinfo "@" ] hostport ]
174
+
175
+ else
176
+ raise InvalidURIError, "bad Gem::URI(is not Gem::URI?): #{uri}"
177
+ end
178
+
179
+ path = '' if !path && !opaque # (see RFC2396 Section 5.2)
180
+ ret = [
181
+ scheme,
182
+ userinfo, host, port, # X
183
+ registry, # X
184
+ path, # Y
185
+ opaque, # Y
186
+ query,
187
+ fragment
188
+ ]
189
+ return ret
190
+ end
191
+
192
+ #
193
+ # == Args
194
+ #
195
+ # +uri+::
196
+ # String
197
+ #
198
+ # == Description
199
+ #
200
+ # Parses +uri+ and constructs either matching Gem::URI scheme object
201
+ # (File, FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or Gem::URI::Generic.
202
+ #
203
+ # == Usage
204
+ #
205
+ # p = Gem::URI::Parser.new
206
+ # p.parse("ldap://ldap.example.com/dc=example?user=john")
207
+ # #=> #<Gem::URI::LDAP ldap://ldap.example.com/dc=example?user=john>
208
+ #
209
+ def parse(uri)
210
+ Gem::URI.for(*self.split(uri), self)
211
+ end
212
+
213
+ #
214
+ # == Args
215
+ #
216
+ # +uris+::
217
+ # an Array of Strings
218
+ #
219
+ # == Description
220
+ #
221
+ # Attempts to parse and merge a set of URIs.
222
+ #
223
+ def join(*uris)
224
+ uris[0] = convert_to_uri(uris[0])
225
+ uris.inject :merge
226
+ end
227
+
228
+ #
229
+ # :call-seq:
230
+ # extract( str )
231
+ # extract( str, schemes )
232
+ # extract( str, schemes ) {|item| block }
233
+ #
234
+ # == Args
235
+ #
236
+ # +str+::
237
+ # String to search
238
+ # +schemes+::
239
+ # Patterns to apply to +str+
240
+ #
241
+ # == Description
242
+ #
243
+ # Attempts to parse and merge a set of URIs.
244
+ # If no +block+ given, then returns the result,
245
+ # else it calls +block+ for each element in result.
246
+ #
247
+ # See also Gem::URI::Parser.make_regexp.
248
+ #
249
+ def extract(str, schemes = nil)
250
+ if block_given?
251
+ str.scan(make_regexp(schemes)) { yield $& }
252
+ nil
253
+ else
254
+ result = []
255
+ str.scan(make_regexp(schemes)) { result.push $& }
256
+ result
257
+ end
258
+ end
259
+
260
+ # Returns Regexp that is default +self.regexp[:ABS_URI_REF]+,
261
+ # unless +schemes+ is provided. Then it is a Regexp.union with +self.pattern[:X_ABS_URI]+.
262
+ def make_regexp(schemes = nil)
263
+ unless schemes
264
+ @regexp[:ABS_URI_REF]
265
+ else
266
+ /(?=#{Regexp.union(*schemes)}:)#{@pattern[:X_ABS_URI]}/x
267
+ end
268
+ end
269
+
270
+ #
271
+ # :call-seq:
272
+ # escape( str )
273
+ # escape( str, unsafe )
274
+ #
275
+ # == Args
276
+ #
277
+ # +str+::
278
+ # String to make safe
279
+ # +unsafe+::
280
+ # Regexp to apply. Defaults to +self.regexp[:UNSAFE]+
281
+ #
282
+ # == Description
283
+ #
284
+ # Constructs a safe String from +str+, removing unsafe characters,
285
+ # replacing them with codes.
286
+ #
287
+ def escape(str, unsafe = @regexp[:UNSAFE])
288
+ unless unsafe.kind_of?(Regexp)
289
+ # perhaps unsafe is String object
290
+ unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
291
+ end
292
+ str.gsub(unsafe) do
293
+ us = $&
294
+ tmp = ''
295
+ us.each_byte do |uc|
296
+ tmp << sprintf('%%%02X', uc)
297
+ end
298
+ tmp
299
+ end.force_encoding(Encoding::US_ASCII)
300
+ end
301
+
302
+ #
303
+ # :call-seq:
304
+ # unescape( str )
305
+ # unescape( str, escaped )
306
+ #
307
+ # == Args
308
+ #
309
+ # +str+::
310
+ # String to remove escapes from
311
+ # +escaped+::
312
+ # Regexp to apply. Defaults to +self.regexp[:ESCAPED]+
313
+ #
314
+ # == Description
315
+ #
316
+ # Removes escapes from +str+.
317
+ #
318
+ def unescape(str, escaped = @regexp[:ESCAPED])
319
+ enc = str.encoding
320
+ enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
321
+ str.gsub(escaped) { [$&[1, 2]].pack('H2').force_encoding(enc) }
322
+ end
323
+
324
+ @@to_s = Kernel.instance_method(:to_s)
325
+ if @@to_s.respond_to?(:bind_call)
326
+ def inspect
327
+ @@to_s.bind_call(self)
328
+ end
329
+ else
330
+ def inspect
331
+ @@to_s.bind(self).call
332
+ end
333
+ end
334
+
335
+ private
336
+
337
+ # Constructs the default Hash of patterns.
338
+ def initialize_pattern(opts = {})
339
+ ret = {}
340
+ ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
341
+ ret[:UNRESERVED] = unreserved = opts.delete(:UNRESERVED) || PATTERN::UNRESERVED
342
+ ret[:RESERVED] = reserved = opts.delete(:RESERVED) || PATTERN::RESERVED
343
+ ret[:DOMLABEL] = opts.delete(:DOMLABEL) || PATTERN::DOMLABEL
344
+ ret[:TOPLABEL] = opts.delete(:TOPLABEL) || PATTERN::TOPLABEL
345
+ ret[:HOSTNAME] = hostname = opts.delete(:HOSTNAME)
346
+
347
+ # RFC 2396 (Gem::URI Generic Syntax)
348
+ # RFC 2732 (IPv6 Literal Addresses in URL's)
349
+ # RFC 2373 (IPv6 Addressing Architecture)
350
+
351
+ # uric = reserved | unreserved | escaped
352
+ ret[:URIC] = uric = "(?:[#{unreserved}#{reserved}]|#{escaped})"
353
+ # uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
354
+ # "&" | "=" | "+" | "$" | ","
355
+ ret[:URIC_NO_SLASH] = uric_no_slash = "(?:[#{unreserved};?:@&=+$,]|#{escaped})"
356
+ # query = *uric
357
+ ret[:QUERY] = query = "#{uric}*"
358
+ # fragment = *uric
359
+ ret[:FRAGMENT] = fragment = "#{uric}*"
360
+
361
+ # hostname = *( domainlabel "." ) toplabel [ "." ]
362
+ # reg-name = *( unreserved / pct-encoded / sub-delims ) # RFC3986
363
+ unless hostname
364
+ ret[:HOSTNAME] = hostname = "(?:[a-zA-Z0-9\\-.]|%\\h\\h)+"
365
+ end
366
+
367
+ # RFC 2373, APPENDIX B:
368
+ # IPv6address = hexpart [ ":" IPv4address ]
369
+ # IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
370
+ # hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
371
+ # hexseq = hex4 *( ":" hex4)
372
+ # hex4 = 1*4HEXDIG
373
+ #
374
+ # XXX: This definition has a flaw. "::" + IPv4address must be
375
+ # allowed too. Here is a replacement.
376
+ #
377
+ # IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
378
+ ret[:IPV4ADDR] = ipv4addr = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
379
+ # hex4 = 1*4HEXDIG
380
+ hex4 = "[#{PATTERN::HEX}]{1,4}"
381
+ # lastpart = hex4 | IPv4address
382
+ lastpart = "(?:#{hex4}|#{ipv4addr})"
383
+ # hexseq1 = *( hex4 ":" ) hex4
384
+ hexseq1 = "(?:#{hex4}:)*#{hex4}"
385
+ # hexseq2 = *( hex4 ":" ) lastpart
386
+ hexseq2 = "(?:#{hex4}:)*#{lastpart}"
387
+ # IPv6address = hexseq2 | [ hexseq1 ] "::" [ hexseq2 ]
388
+ ret[:IPV6ADDR] = ipv6addr = "(?:#{hexseq2}|(?:#{hexseq1})?::(?:#{hexseq2})?)"
389
+
390
+ # IPv6prefix = ( hexseq1 | [ hexseq1 ] "::" [ hexseq1 ] ) "/" 1*2DIGIT
391
+ # unused
392
+
393
+ # ipv6reference = "[" IPv6address "]" (RFC 2732)
394
+ ret[:IPV6REF] = ipv6ref = "\\[#{ipv6addr}\\]"
395
+
396
+ # host = hostname | IPv4address
397
+ # host = hostname | IPv4address | IPv6reference (RFC 2732)
398
+ ret[:HOST] = host = "(?:#{hostname}|#{ipv4addr}|#{ipv6ref})"
399
+ # port = *digit
400
+ ret[:PORT] = port = '\d*'
401
+ # hostport = host [ ":" port ]
402
+ ret[:HOSTPORT] = hostport = "#{host}(?::#{port})?"
403
+
404
+ # userinfo = *( unreserved | escaped |
405
+ # ";" | ":" | "&" | "=" | "+" | "$" | "," )
406
+ ret[:USERINFO] = userinfo = "(?:[#{unreserved};:&=+$,]|#{escaped})*"
407
+
408
+ # pchar = unreserved | escaped |
409
+ # ":" | "@" | "&" | "=" | "+" | "$" | ","
410
+ pchar = "(?:[#{unreserved}:@&=+$,]|#{escaped})"
411
+ # param = *pchar
412
+ param = "#{pchar}*"
413
+ # segment = *pchar *( ";" param )
414
+ segment = "#{pchar}*(?:;#{param})*"
415
+ # path_segments = segment *( "/" segment )
416
+ ret[:PATH_SEGMENTS] = path_segments = "#{segment}(?:/#{segment})*"
417
+
418
+ # server = [ [ userinfo "@" ] hostport ]
419
+ server = "(?:#{userinfo}@)?#{hostport}"
420
+ # reg_name = 1*( unreserved | escaped | "$" | "," |
421
+ # ";" | ":" | "@" | "&" | "=" | "+" )
422
+ ret[:REG_NAME] = reg_name = "(?:[#{unreserved}$,;:@&=+]|#{escaped})+"
423
+ # authority = server | reg_name
424
+ authority = "(?:#{server}|#{reg_name})"
425
+
426
+ # rel_segment = 1*( unreserved | escaped |
427
+ # ";" | "@" | "&" | "=" | "+" | "$" | "," )
428
+ ret[:REL_SEGMENT] = rel_segment = "(?:[#{unreserved};@&=+$,]|#{escaped})+"
429
+
430
+ # scheme = alpha *( alpha | digit | "+" | "-" | "." )
431
+ ret[:SCHEME] = scheme = "[#{PATTERN::ALPHA}][\\-+.#{PATTERN::ALPHA}\\d]*"
432
+
433
+ # abs_path = "/" path_segments
434
+ ret[:ABS_PATH] = abs_path = "/#{path_segments}"
435
+ # rel_path = rel_segment [ abs_path ]
436
+ ret[:REL_PATH] = rel_path = "#{rel_segment}(?:#{abs_path})?"
437
+ # net_path = "//" authority [ abs_path ]
438
+ ret[:NET_PATH] = net_path = "//#{authority}(?:#{abs_path})?"
439
+
440
+ # hier_part = ( net_path | abs_path ) [ "?" query ]
441
+ ret[:HIER_PART] = hier_part = "(?:#{net_path}|#{abs_path})(?:\\?(?:#{query}))?"
442
+ # opaque_part = uric_no_slash *uric
443
+ ret[:OPAQUE_PART] = opaque_part = "#{uric_no_slash}#{uric}*"
444
+
445
+ # absoluteURI = scheme ":" ( hier_part | opaque_part )
446
+ ret[:ABS_URI] = abs_uri = "#{scheme}:(?:#{hier_part}|#{opaque_part})"
447
+ # relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
448
+ ret[:REL_URI] = rel_uri = "(?:#{net_path}|#{abs_path}|#{rel_path})(?:\\?#{query})?"
449
+
450
+ # Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
451
+ ret[:URI_REF] = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
452
+
453
+ ret[:X_ABS_URI] = "
454
+ (#{scheme}): (?# 1: scheme)
455
+ (?:
456
+ (#{opaque_part}) (?# 2: opaque)
457
+ |
458
+ (?:(?:
459
+ //(?:
460
+ (?:(?:(#{userinfo})@)? (?# 3: userinfo)
461
+ (?:(#{host})(?::(\\d*))?))? (?# 4: host, 5: port)
462
+ |
463
+ (#{reg_name}) (?# 6: registry)
464
+ )
465
+ |
466
+ (?!//)) (?# XXX: '//' is the mark for hostport)
467
+ (#{abs_path})? (?# 7: path)
468
+ )(?:\\?(#{query}))? (?# 8: query)
469
+ )
470
+ (?:\\#(#{fragment}))? (?# 9: fragment)
471
+ "
472
+
473
+ ret[:X_REL_URI] = "
474
+ (?:
475
+ (?:
476
+ //
477
+ (?:
478
+ (?:(#{userinfo})@)? (?# 1: userinfo)
479
+ (#{host})?(?::(\\d*))? (?# 2: host, 3: port)
480
+ |
481
+ (#{reg_name}) (?# 4: registry)
482
+ )
483
+ )
484
+ |
485
+ (#{rel_segment}) (?# 5: rel_segment)
486
+ )?
487
+ (#{abs_path})? (?# 6: abs_path)
488
+ (?:\\?(#{query}))? (?# 7: query)
489
+ (?:\\#(#{fragment}))? (?# 8: fragment)
490
+ "
491
+
492
+ ret
493
+ end
494
+
495
+ # Constructs the default Hash of Regexp's.
496
+ def initialize_regexp(pattern)
497
+ ret = {}
498
+
499
+ # for Gem::URI::split
500
+ ret[:ABS_URI] = Regexp.new('\A\s*+' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
501
+ ret[:REL_URI] = Regexp.new('\A\s*+' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
502
+
503
+ # for Gem::URI::extract
504
+ ret[:URI_REF] = Regexp.new(pattern[:URI_REF])
505
+ ret[:ABS_URI_REF] = Regexp.new(pattern[:X_ABS_URI], Regexp::EXTENDED)
506
+ ret[:REL_URI_REF] = Regexp.new(pattern[:X_REL_URI], Regexp::EXTENDED)
507
+
508
+ # for Gem::URI::escape/unescape
509
+ ret[:ESCAPED] = Regexp.new(pattern[:ESCAPED])
510
+ ret[:UNSAFE] = Regexp.new("[^#{pattern[:UNRESERVED]}#{pattern[:RESERVED]}]")
511
+
512
+ # for Generic#initialize
513
+ ret[:SCHEME] = Regexp.new("\\A#{pattern[:SCHEME]}\\z")
514
+ ret[:USERINFO] = Regexp.new("\\A#{pattern[:USERINFO]}\\z")
515
+ ret[:HOST] = Regexp.new("\\A#{pattern[:HOST]}\\z")
516
+ ret[:PORT] = Regexp.new("\\A#{pattern[:PORT]}\\z")
517
+ ret[:OPAQUE] = Regexp.new("\\A#{pattern[:OPAQUE_PART]}\\z")
518
+ ret[:REGISTRY] = Regexp.new("\\A#{pattern[:REG_NAME]}\\z")
519
+ ret[:ABS_PATH] = Regexp.new("\\A#{pattern[:ABS_PATH]}\\z")
520
+ ret[:REL_PATH] = Regexp.new("\\A#{pattern[:REL_PATH]}\\z")
521
+ ret[:QUERY] = Regexp.new("\\A#{pattern[:QUERY]}\\z")
522
+ ret[:FRAGMENT] = Regexp.new("\\A#{pattern[:FRAGMENT]}\\z")
523
+
524
+ ret
525
+ end
526
+
527
+ def convert_to_uri(uri)
528
+ if uri.is_a?(Gem::URI::Generic)
529
+ uri
530
+ elsif uri = String.try_convert(uri)
531
+ parse(uri)
532
+ else
533
+ raise ArgumentError,
534
+ "bad argument (expected Gem::URI object or Gem::URI string)"
535
+ end
536
+ end
537
+
538
+ end # class Parser
539
+ end # module Gem::URI