bundler 1.17.3 → 2.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (426) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3354 -1258
  3. data/LICENSE.md +18 -19
  4. data/README.md +10 -15
  5. data/bundler.gemspec +15 -33
  6. data/exe/bundle +8 -10
  7. data/exe/bundler +1 -1
  8. data/lib/bundler/.document +1 -0
  9. data/lib/bundler/build_metadata.rb +5 -13
  10. data/lib/bundler/capistrano.rb +5 -5
  11. data/lib/bundler/checksum.rb +254 -0
  12. data/lib/bundler/ci_detector.rb +75 -0
  13. data/lib/bundler/cli/add.rb +29 -15
  14. data/lib/bundler/cli/binstubs.rb +13 -5
  15. data/lib/bundler/cli/cache.rb +24 -17
  16. data/lib/bundler/cli/check.rb +7 -5
  17. data/lib/bundler/cli/clean.rb +1 -1
  18. data/lib/bundler/cli/common.rb +50 -14
  19. data/lib/bundler/cli/config.rb +171 -86
  20. data/lib/bundler/cli/console.rb +3 -6
  21. data/lib/bundler/cli/doctor.rb +29 -12
  22. data/lib/bundler/cli/exec.rb +9 -25
  23. data/lib/bundler/cli/fund.rb +36 -0
  24. data/lib/bundler/cli/gem.rb +268 -53
  25. data/lib/bundler/cli/info.rb +51 -18
  26. data/lib/bundler/cli/init.rb +7 -3
  27. data/lib/bundler/cli/inject.rb +2 -2
  28. data/lib/bundler/cli/install.rb +55 -73
  29. data/lib/bundler/cli/issue.rb +9 -8
  30. data/lib/bundler/cli/list.rb +19 -11
  31. data/lib/bundler/cli/lock.rb +56 -26
  32. data/lib/bundler/cli/open.rb +10 -7
  33. data/lib/bundler/cli/outdated.rb +159 -128
  34. data/lib/bundler/cli/platform.rb +8 -6
  35. data/lib/bundler/cli/plugin.rb +23 -12
  36. data/lib/bundler/cli/pristine.rb +39 -26
  37. data/lib/bundler/cli/remove.rb +1 -2
  38. data/lib/bundler/cli/show.rb +7 -7
  39. data/lib/bundler/cli/update.rb +51 -19
  40. data/lib/bundler/cli/viz.rb +1 -1
  41. data/lib/bundler/cli.rb +399 -390
  42. data/lib/bundler/compact_index_client/cache.rb +55 -77
  43. data/lib/bundler/compact_index_client/cache_file.rb +148 -0
  44. data/lib/bundler/compact_index_client/gem_parser.rb +32 -0
  45. data/lib/bundler/compact_index_client/parser.rb +84 -0
  46. data/lib/bundler/compact_index_client/updater.rb +72 -84
  47. data/lib/bundler/compact_index_client.rb +61 -73
  48. data/lib/bundler/constants.rb +9 -2
  49. data/lib/bundler/current_ruby.rb +20 -21
  50. data/lib/bundler/definition.rb +663 -505
  51. data/lib/bundler/dependency.rb +38 -71
  52. data/lib/bundler/deployment.rb +1 -1
  53. data/lib/bundler/digest.rb +71 -0
  54. data/lib/bundler/dsl.rb +171 -152
  55. data/lib/bundler/endpoint_specification.rb +43 -17
  56. data/lib/bundler/env.rb +11 -18
  57. data/lib/bundler/environment_preserver.rb +17 -8
  58. data/lib/bundler/errors.rb +115 -14
  59. data/lib/bundler/feature_flag.rb +15 -39
  60. data/lib/bundler/fetcher/base.rb +12 -12
  61. data/lib/bundler/fetcher/compact_index.rb +41 -47
  62. data/lib/bundler/fetcher/dependency.rb +4 -8
  63. data/lib/bundler/fetcher/downloader.rb +27 -20
  64. data/lib/bundler/fetcher/gem_remote_fetcher.rb +16 -0
  65. data/lib/bundler/fetcher/index.rb +6 -33
  66. data/lib/bundler/fetcher.rb +109 -90
  67. data/lib/bundler/force_platform.rb +16 -0
  68. data/lib/bundler/friendly_errors.rb +50 -55
  69. data/lib/bundler/gem_helper.rb +81 -46
  70. data/lib/bundler/gem_helpers.rb +78 -29
  71. data/lib/bundler/gem_tasks.rb +1 -1
  72. data/lib/bundler/gem_version_promoter.rb +68 -109
  73. data/lib/bundler/graph.rb +11 -11
  74. data/lib/bundler/index.rb +74 -82
  75. data/lib/bundler/injector.rb +58 -26
  76. data/lib/bundler/inline.rb +59 -35
  77. data/lib/bundler/installer/gem_installer.rb +29 -29
  78. data/lib/bundler/installer/parallel_installer.rb +38 -68
  79. data/lib/bundler/installer/standalone.rb +76 -16
  80. data/lib/bundler/installer.rb +60 -135
  81. data/lib/bundler/lazy_specification.rb +161 -63
  82. data/lib/bundler/lockfile_generator.rb +14 -5
  83. data/lib/bundler/lockfile_parser.rb +150 -109
  84. data/lib/bundler/man/bundle-add.1 +76 -0
  85. data/lib/bundler/man/bundle-add.1.ronn +87 -0
  86. data/{man → lib/bundler/man}/bundle-binstubs.1 +15 -22
  87. data/{man/bundle-binstubs.ronn → lib/bundler/man/bundle-binstubs.1.ronn} +8 -7
  88. data/lib/bundler/man/bundle-cache.1 +68 -0
  89. data/lib/bundler/man/bundle-cache.1.ronn +108 -0
  90. data/{man → lib/bundler/man}/bundle-check.1 +7 -14
  91. data/{man/bundle-check.ronn → lib/bundler/man/bundle-check.1.ronn} +7 -2
  92. data/{man → lib/bundler/man}/bundle-clean.1 +4 -11
  93. data/{man/bundle-clean.ronn → lib/bundler/man/bundle-clean.1.ronn} +1 -1
  94. data/{man → lib/bundler/man}/bundle-config.1 +80 -260
  95. data/{man/bundle-config.ronn → lib/bundler/man/bundle-config.1.ronn} +104 -98
  96. data/lib/bundler/man/bundle-console.1 +33 -0
  97. data/lib/bundler/man/bundle-console.1.ronn +39 -0
  98. data/{man → lib/bundler/man}/bundle-doctor.1 +5 -19
  99. data/{man/bundle-doctor.ronn → lib/bundler/man/bundle-doctor.1.ronn} +1 -1
  100. data/lib/bundler/man/bundle-env.1 +9 -0
  101. data/lib/bundler/man/bundle-env.1.ronn +10 -0
  102. data/{man → lib/bundler/man}/bundle-exec.1 +20 -78
  103. data/{man/bundle-exec.ronn → lib/bundler/man/bundle-exec.1.ronn} +12 -10
  104. data/lib/bundler/man/bundle-fund.1 +22 -0
  105. data/lib/bundler/man/bundle-fund.1.ronn +25 -0
  106. data/lib/bundler/man/bundle-gem.1 +87 -0
  107. data/lib/bundler/man/bundle-gem.1.ronn +149 -0
  108. data/lib/bundler/man/bundle-help.1 +9 -0
  109. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  110. data/lib/bundler/man/bundle-info.1 +17 -0
  111. data/lib/bundler/man/bundle-info.1.ronn +21 -0
  112. data/{man → lib/bundler/man}/bundle-init.1 +8 -13
  113. data/{man/bundle-init.ronn → lib/bundler/man/bundle-init.1.ronn} +5 -2
  114. data/lib/bundler/man/bundle-inject.1 +31 -0
  115. data/{man/bundle-inject.ronn → lib/bundler/man/bundle-inject.1.ronn} +12 -2
  116. data/{man → lib/bundler/man}/bundle-install.1 +65 -155
  117. data/{man/bundle-install.ronn → lib/bundler/man/bundle-install.1.ronn} +66 -57
  118. data/lib/bundler/man/bundle-issue.1 +45 -0
  119. data/lib/bundler/man/bundle-issue.1.ronn +37 -0
  120. data/lib/bundler/man/bundle-licenses.1 +9 -0
  121. data/lib/bundler/man/bundle-licenses.1.ronn +10 -0
  122. data/{man → lib/bundler/man}/bundle-list.1 +9 -24
  123. data/{man/bundle-list.ronn → lib/bundler/man/bundle-list.1.ronn} +10 -7
  124. data/{man → lib/bundler/man}/bundle-lock.1 +25 -34
  125. data/{man/bundle-lock.ronn → lib/bundler/man/bundle-lock.1.ronn} +25 -4
  126. data/lib/bundler/man/bundle-open.1 +32 -0
  127. data/{man/bundle-open.ronn → lib/bundler/man/bundle-open.1.ronn} +10 -1
  128. data/{man → lib/bundler/man}/bundle-outdated.1 +23 -75
  129. data/{man/bundle-outdated.ronn → lib/bundler/man/bundle-outdated.1.ronn} +21 -22
  130. data/lib/bundler/man/bundle-platform.1 +49 -0
  131. data/{man/bundle-platform.ronn → lib/bundler/man/bundle-platform.1.ronn} +14 -7
  132. data/lib/bundler/man/bundle-plugin.1 +58 -0
  133. data/lib/bundler/man/bundle-plugin.1.ronn +63 -0
  134. data/{man → lib/bundler/man}/bundle-pristine.1 +5 -16
  135. data/{man/bundle-pristine.ronn → lib/bundler/man/bundle-pristine.1.ronn} +1 -1
  136. data/{man → lib/bundler/man}/bundle-remove.1 +4 -14
  137. data/{man/bundle-remove.ronn → lib/bundler/man/bundle-remove.1.ronn} +1 -1
  138. data/{man → lib/bundler/man}/bundle-show.1 +7 -11
  139. data/{man/bundle-show.ronn → lib/bundler/man/bundle-show.1.ronn} +4 -0
  140. data/{man → lib/bundler/man}/bundle-update.1 +35 -148
  141. data/{man/bundle-update.ronn → lib/bundler/man/bundle-update.1.ronn} +21 -12
  142. data/lib/bundler/man/bundle-version.1 +22 -0
  143. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  144. data/{man → lib/bundler/man}/bundle-viz.1 +9 -18
  145. data/{man/bundle-viz.ronn → lib/bundler/man/bundle-viz.1.ronn} +9 -3
  146. data/{man → lib/bundler/man}/bundle.1 +19 -53
  147. data/{man/bundle.ronn → lib/bundler/man/bundle.1.ronn} +14 -9
  148. data/{man → lib/bundler/man}/gemfile.5 +139 -356
  149. data/{man → lib/bundler/man}/gemfile.5.ronn +134 -97
  150. data/{man → lib/bundler/man}/index.txt +9 -1
  151. data/lib/bundler/match_metadata.rb +17 -0
  152. data/lib/bundler/match_platform.rb +2 -3
  153. data/lib/bundler/match_remote_metadata.rb +29 -0
  154. data/lib/bundler/materialization.rb +59 -0
  155. data/lib/bundler/mirror.rb +10 -12
  156. data/lib/bundler/plugin/api/source.rb +34 -18
  157. data/lib/bundler/plugin/api.rb +1 -1
  158. data/lib/bundler/plugin/dsl.rb +1 -1
  159. data/lib/bundler/plugin/events.rb +24 -0
  160. data/lib/bundler/plugin/index.rb +44 -9
  161. data/lib/bundler/plugin/installer/git.rb +0 -4
  162. data/lib/bundler/plugin/installer/path.rb +18 -0
  163. data/lib/bundler/plugin/installer/rubygems.rb +1 -9
  164. data/lib/bundler/plugin/installer.rb +63 -27
  165. data/lib/bundler/plugin/source_list.rb +5 -1
  166. data/lib/bundler/plugin.rb +131 -45
  167. data/lib/bundler/process_lock.rb +10 -14
  168. data/lib/bundler/remote_specification.rb +22 -10
  169. data/lib/bundler/resolver/base.rb +118 -0
  170. data/lib/bundler/resolver/candidate.rb +82 -0
  171. data/lib/bundler/resolver/incompatibility.rb +15 -0
  172. data/lib/bundler/resolver/package.rb +90 -0
  173. data/lib/bundler/resolver/root.rb +25 -0
  174. data/lib/bundler/resolver/spec_group.rb +60 -68
  175. data/lib/bundler/resolver.rb +454 -303
  176. data/lib/bundler/retry.rb +6 -6
  177. data/lib/bundler/ruby_dsl.rb +51 -7
  178. data/lib/bundler/ruby_version.rb +23 -38
  179. data/lib/bundler/rubygems_ext.rb +357 -98
  180. data/lib/bundler/rubygems_gem_installer.rb +131 -65
  181. data/lib/bundler/rubygems_integration.rb +149 -591
  182. data/lib/bundler/runtime.rb +51 -51
  183. data/lib/bundler/safe_marshal.rb +31 -0
  184. data/lib/bundler/self_manager.rb +206 -0
  185. data/lib/bundler/settings.rb +271 -135
  186. data/lib/bundler/setup.rb +23 -12
  187. data/lib/bundler/shared_helpers.rb +127 -117
  188. data/lib/bundler/similarity_detector.rb +3 -3
  189. data/lib/bundler/source/git/git_proxy.rb +326 -127
  190. data/lib/bundler/source/git.rb +207 -88
  191. data/lib/bundler/source/metadata.rb +19 -18
  192. data/lib/bundler/source/path/installer.rb +11 -32
  193. data/lib/bundler/source/path.rb +39 -38
  194. data/lib/bundler/source/rubygems/remote.rb +3 -4
  195. data/lib/bundler/source/rubygems.rb +223 -255
  196. data/lib/bundler/source/rubygems_aggregate.rb +68 -0
  197. data/lib/bundler/source.rb +33 -11
  198. data/lib/bundler/source_list.rb +131 -66
  199. data/lib/bundler/source_map.rb +71 -0
  200. data/lib/bundler/spec_set.rb +239 -94
  201. data/lib/bundler/stub_specification.rb +77 -39
  202. data/lib/bundler/templates/Executable +3 -5
  203. data/lib/bundler/templates/Executable.bundler +23 -19
  204. data/lib/bundler/templates/Executable.standalone +4 -4
  205. data/lib/bundler/templates/Gemfile +0 -2
  206. data/lib/bundler/templates/newgem/CHANGELOG.md.tt +5 -0
  207. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +104 -46
  208. data/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  209. data/lib/bundler/templates/newgem/Gemfile.tt +19 -2
  210. data/lib/bundler/templates/newgem/README.md.tt +18 -16
  211. data/lib/bundler/templates/newgem/Rakefile.tt +44 -6
  212. data/lib/bundler/templates/newgem/bin/console.tt +1 -4
  213. data/lib/bundler/templates/newgem/circleci/config.yml.tt +25 -0
  214. data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  215. data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  216. data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  217. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +1 -1
  218. data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  219. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +37 -0
  220. data/lib/bundler/templates/newgem/gitignore.tt +3 -0
  221. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +18 -0
  222. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +2 -0
  223. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +4 -2
  224. data/lib/bundler/templates/newgem/newgem.gemspec.tt +37 -40
  225. data/lib/bundler/templates/newgem/rubocop.yml.tt +8 -0
  226. data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  227. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +2 -0
  228. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -1
  229. data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  230. data/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt +6 -0
  231. data/lib/bundler/templates/newgem/test/{newgem_test.rb.tt → minitest/test_newgem.rb.tt} +3 -1
  232. data/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +15 -0
  233. data/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +6 -0
  234. data/lib/bundler/ui/rg_proxy.rb +2 -2
  235. data/lib/bundler/ui/shell.rb +64 -23
  236. data/lib/bundler/ui/silent.rb +33 -6
  237. data/lib/bundler/ui.rb +3 -3
  238. data/lib/bundler/uri_credentials_filter.rb +11 -5
  239. data/lib/bundler/uri_normalizer.rb +23 -0
  240. data/lib/bundler/vendor/.document +1 -0
  241. data/lib/bundler/vendor/connection_pool/.document +1 -0
  242. data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  243. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +174 -0
  244. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
  245. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
  246. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +175 -0
  247. data/lib/bundler/vendor/fileutils/.document +1 -0
  248. data/lib/bundler/vendor/fileutils/COPYING +56 -0
  249. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1490 -432
  250. data/lib/bundler/vendor/net-http-persistent/.document +1 -0
  251. data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  252. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +41 -0
  253. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +65 -0
  254. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  255. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +362 -484
  256. data/lib/bundler/vendor/pub_grub/.document +1 -0
  257. data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  258. data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  259. data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  260. data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  261. data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  262. data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  263. data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  264. data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  265. data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  266. data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +61 -0
  267. data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  268. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  269. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  270. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
  271. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
  272. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  273. data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  274. data/lib/bundler/vendor/securerandom/.document +1 -0
  275. data/lib/bundler/vendor/securerandom/COPYING +56 -0
  276. data/lib/bundler/vendor/securerandom/lib/securerandom.rb +102 -0
  277. data/lib/bundler/vendor/thor/.document +1 -0
  278. data/lib/bundler/vendor/thor/LICENSE.md +20 -0
  279. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +4 -3
  280. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +3 -2
  281. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +8 -18
  282. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +1 -1
  283. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +27 -20
  284. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +34 -13
  285. data/lib/bundler/vendor/thor/lib/thor/actions.rb +47 -28
  286. data/lib/bundler/vendor/thor/lib/thor/base.rb +200 -54
  287. data/lib/bundler/vendor/thor/lib/thor/command.rb +34 -18
  288. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +10 -0
  289. data/lib/bundler/vendor/thor/lib/thor/error.rb +74 -0
  290. data/lib/bundler/vendor/thor/lib/thor/group.rb +15 -4
  291. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +2 -1
  292. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +1 -1
  293. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +6 -6
  294. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +2 -2
  295. data/lib/bundler/vendor/thor/lib/thor/nested_context.rb +29 -0
  296. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +17 -1
  297. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +35 -15
  298. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +45 -13
  299. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +86 -13
  300. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -4
  301. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +3 -2
  302. data/lib/bundler/vendor/thor/lib/thor/runner.rb +51 -40
  303. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +99 -148
  304. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +6 -43
  305. data/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  306. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +4 -49
  307. data/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +118 -0
  308. data/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  309. data/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  310. data/lib/bundler/vendor/thor/lib/thor/shell.rb +6 -6
  311. data/lib/bundler/vendor/thor/lib/thor/util.rb +26 -9
  312. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  313. data/lib/bundler/vendor/thor/lib/thor.rb +182 -17
  314. data/lib/bundler/vendor/tsort/.document +1 -0
  315. data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  316. data/lib/bundler/vendor/tsort/lib/tsort.rb +455 -0
  317. data/lib/bundler/vendor/uri/.document +1 -0
  318. data/lib/bundler/vendor/uri/COPYING +56 -0
  319. data/lib/bundler/vendor/uri/lib/uri/common.rb +876 -0
  320. data/lib/bundler/vendor/uri/lib/uri/file.rb +100 -0
  321. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +267 -0
  322. data/lib/bundler/vendor/uri/lib/uri/generic.rb +1578 -0
  323. data/lib/bundler/vendor/uri/lib/uri/http.rb +125 -0
  324. data/lib/bundler/vendor/uri/lib/uri/https.rb +23 -0
  325. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +261 -0
  326. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +22 -0
  327. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +293 -0
  328. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +546 -0
  329. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +206 -0
  330. data/lib/bundler/vendor/uri/lib/uri/version.rb +6 -0
  331. data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
  332. data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
  333. data/lib/bundler/vendor/uri/lib/uri.rb +104 -0
  334. data/lib/bundler/vendored_fileutils.rb +1 -6
  335. data/lib/bundler/vendored_net_http.rb +23 -0
  336. data/lib/bundler/vendored_persistent.rb +1 -42
  337. data/lib/bundler/{vendored_molinillo.rb → vendored_pub_grub.rb} +1 -1
  338. data/lib/bundler/vendored_securerandom.rb +12 -0
  339. data/lib/bundler/vendored_thor.rb +2 -2
  340. data/lib/bundler/vendored_timeout.rb +12 -0
  341. data/lib/bundler/vendored_tsort.rb +4 -0
  342. data/lib/bundler/vendored_uri.rb +21 -0
  343. data/lib/bundler/version.rb +5 -20
  344. data/lib/bundler/vlad.rb +3 -3
  345. data/lib/bundler/worker.rb +26 -15
  346. data/lib/bundler/yaml_serializer.rb +21 -13
  347. data/lib/bundler.rb +364 -230
  348. metadata +186 -218
  349. data/exe/bundle_ruby +0 -60
  350. data/lib/bundler/cli/package.rb +0 -49
  351. data/lib/bundler/compatibility_guard.rb +0 -14
  352. data/lib/bundler/dep_proxy.rb +0 -48
  353. data/lib/bundler/gem_remote_fetcher.rb +0 -43
  354. data/lib/bundler/gemdeps.rb +0 -29
  355. data/lib/bundler/psyched_yaml.rb +0 -37
  356. data/lib/bundler/ssl_certs/certificate_manager.rb +0 -66
  357. data/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +0 -21
  358. data/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +0 -23
  359. data/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +0 -25
  360. data/lib/bundler/templates/gems.rb +0 -8
  361. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +0 -3
  362. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +0 -4
  363. data/lib/bundler/templates/newgem/travis.yml.tt +0 -7
  364. data/lib/bundler/vendor/molinillo/lib/molinillo/compatibility.rb +0 -26
  365. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  366. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -81
  367. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
  368. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
  369. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
  370. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
  371. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
  372. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
  373. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
  374. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
  375. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -136
  376. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -223
  377. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -143
  378. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  379. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -101
  380. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
  381. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -837
  382. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
  383. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
  384. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -12
  385. data/lib/bundler/vendor/net-http-persistent/lib/net/http/faster.rb +0 -27
  386. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse.rb +0 -129
  387. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +0 -12
  388. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +0 -129
  389. data/lib/bundler/version_ranges.rb +0 -76
  390. data/man/bundle-add.1 +0 -58
  391. data/man/bundle-add.1.txt +0 -52
  392. data/man/bundle-add.ronn +0 -40
  393. data/man/bundle-binstubs.1.txt +0 -48
  394. data/man/bundle-check.1.txt +0 -33
  395. data/man/bundle-clean.1.txt +0 -26
  396. data/man/bundle-config.1.txt +0 -529
  397. data/man/bundle-doctor.1.txt +0 -44
  398. data/man/bundle-exec.1.txt +0 -178
  399. data/man/bundle-gem.1 +0 -80
  400. data/man/bundle-gem.1.txt +0 -91
  401. data/man/bundle-gem.ronn +0 -78
  402. data/man/bundle-info.1 +0 -20
  403. data/man/bundle-info.1.txt +0 -21
  404. data/man/bundle-info.ronn +0 -17
  405. data/man/bundle-init.1.txt +0 -34
  406. data/man/bundle-inject.1 +0 -33
  407. data/man/bundle-inject.1.txt +0 -32
  408. data/man/bundle-install.1.txt +0 -396
  409. data/man/bundle-list.1.txt +0 -43
  410. data/man/bundle-lock.1.txt +0 -93
  411. data/man/bundle-open.1 +0 -32
  412. data/man/bundle-open.1.txt +0 -29
  413. data/man/bundle-outdated.1.txt +0 -131
  414. data/man/bundle-package.1 +0 -55
  415. data/man/bundle-package.1.txt +0 -79
  416. data/man/bundle-package.ronn +0 -72
  417. data/man/bundle-platform.1 +0 -61
  418. data/man/bundle-platform.1.txt +0 -57
  419. data/man/bundle-pristine.1.txt +0 -44
  420. data/man/bundle-remove.1.txt +0 -34
  421. data/man/bundle-show.1.txt +0 -27
  422. data/man/bundle-update.1.txt +0 -391
  423. data/man/bundle-viz.1.txt +0 -39
  424. data/man/bundle.1.txt +0 -116
  425. data/man/gemfile.5.txt +0 -653
  426. /data/lib/bundler/{ssl_certs → man}/.document +0 -0
@@ -0,0 +1,1578 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = uri/generic.rb
4
+ #
5
+ # Author:: Akira Yamada <akira@ruby-lang.org>
6
+ # License:: You can redistribute it and/or modify it under the same term as Ruby.
7
+ #
8
+ # See Bundler::URI for general documentation
9
+ #
10
+
11
+ require_relative 'common'
12
+ autoload :IPSocket, 'socket'
13
+ autoload :IPAddr, 'ipaddr'
14
+
15
+ module Bundler::URI
16
+
17
+ #
18
+ # Base class for all Bundler::URI classes.
19
+ # Implements generic Bundler::URI syntax as per RFC 2396.
20
+ #
21
+ class Generic
22
+ include Bundler::URI
23
+
24
+ #
25
+ # A Default port of nil for Bundler::URI::Generic.
26
+ #
27
+ DEFAULT_PORT = nil
28
+
29
+ #
30
+ # Returns default port.
31
+ #
32
+ def self.default_port
33
+ self::DEFAULT_PORT
34
+ end
35
+
36
+ #
37
+ # Returns default port.
38
+ #
39
+ def default_port
40
+ self.class.default_port
41
+ end
42
+
43
+ #
44
+ # An Array of the available components for Bundler::URI::Generic.
45
+ #
46
+ COMPONENT = [
47
+ :scheme,
48
+ :userinfo, :host, :port, :registry,
49
+ :path, :opaque,
50
+ :query,
51
+ :fragment
52
+ ].freeze
53
+
54
+ #
55
+ # Components of the Bundler::URI in the order.
56
+ #
57
+ def self.component
58
+ self::COMPONENT
59
+ end
60
+
61
+ USE_REGISTRY = false # :nodoc:
62
+
63
+ def self.use_registry # :nodoc:
64
+ self::USE_REGISTRY
65
+ end
66
+
67
+ #
68
+ # == Synopsis
69
+ #
70
+ # See ::new.
71
+ #
72
+ # == Description
73
+ #
74
+ # At first, tries to create a new Bundler::URI::Generic instance using
75
+ # Bundler::URI::Generic::build. But, if exception Bundler::URI::InvalidComponentError is raised,
76
+ # then it does Bundler::URI::Escape.escape all Bundler::URI components and tries again.
77
+ #
78
+ def self.build2(args)
79
+ begin
80
+ return self.build(args)
81
+ rescue InvalidComponentError
82
+ if args.kind_of?(Array)
83
+ return self.build(args.collect{|x|
84
+ if x.is_a?(String)
85
+ Bundler::URI::RFC2396_PARSER.escape(x)
86
+ else
87
+ x
88
+ end
89
+ })
90
+ elsif args.kind_of?(Hash)
91
+ tmp = {}
92
+ args.each do |key, value|
93
+ tmp[key] = if value
94
+ Bundler::URI::RFC2396_PARSER.escape(value)
95
+ else
96
+ value
97
+ end
98
+ end
99
+ return self.build(tmp)
100
+ end
101
+ end
102
+ end
103
+
104
+ #
105
+ # == Synopsis
106
+ #
107
+ # See ::new.
108
+ #
109
+ # == Description
110
+ #
111
+ # Creates a new Bundler::URI::Generic instance from components of Bundler::URI::Generic
112
+ # with check. Components are: scheme, userinfo, host, port, registry, path,
113
+ # opaque, query, and fragment. You can provide arguments either by an Array or a Hash.
114
+ # See ::new for hash keys to use or for order of array items.
115
+ #
116
+ def self.build(args)
117
+ if args.kind_of?(Array) &&
118
+ args.size == ::Bundler::URI::Generic::COMPONENT.size
119
+ tmp = args.dup
120
+ elsif args.kind_of?(Hash)
121
+ tmp = ::Bundler::URI::Generic::COMPONENT.collect do |c|
122
+ if args.include?(c)
123
+ args[c]
124
+ else
125
+ nil
126
+ end
127
+ end
128
+ else
129
+ component = self.class.component rescue ::Bundler::URI::Generic::COMPONENT
130
+ raise ArgumentError,
131
+ "expected Array of or Hash of components of #{self.class} (#{component.join(', ')})"
132
+ end
133
+
134
+ tmp << nil
135
+ tmp << true
136
+ return self.new(*tmp)
137
+ end
138
+
139
+ #
140
+ # == Args
141
+ #
142
+ # +scheme+::
143
+ # Protocol scheme, i.e. 'http','ftp','mailto' and so on.
144
+ # +userinfo+::
145
+ # User name and password, i.e. 'sdmitry:bla'.
146
+ # +host+::
147
+ # Server host name.
148
+ # +port+::
149
+ # Server port.
150
+ # +registry+::
151
+ # Registry of naming authorities.
152
+ # +path+::
153
+ # Path on server.
154
+ # +opaque+::
155
+ # Opaque part.
156
+ # +query+::
157
+ # Query data.
158
+ # +fragment+::
159
+ # Part of the Bundler::URI after '#' character.
160
+ # +parser+::
161
+ # Parser for internal use [Bundler::URI::DEFAULT_PARSER by default].
162
+ # +arg_check+::
163
+ # Check arguments [false by default].
164
+ #
165
+ # == Description
166
+ #
167
+ # Creates a new Bundler::URI::Generic instance from ``generic'' components without check.
168
+ #
169
+ def initialize(scheme,
170
+ userinfo, host, port, registry,
171
+ path, opaque,
172
+ query,
173
+ fragment,
174
+ parser = DEFAULT_PARSER,
175
+ arg_check = false)
176
+ @scheme = nil
177
+ @user = nil
178
+ @password = nil
179
+ @host = nil
180
+ @port = nil
181
+ @path = nil
182
+ @query = nil
183
+ @opaque = nil
184
+ @fragment = nil
185
+ @parser = parser == DEFAULT_PARSER ? nil : parser
186
+
187
+ if arg_check
188
+ self.scheme = scheme
189
+ self.userinfo = userinfo
190
+ self.hostname = host
191
+ self.port = port
192
+ self.path = path
193
+ self.query = query
194
+ self.opaque = opaque
195
+ self.fragment = fragment
196
+ else
197
+ self.set_scheme(scheme)
198
+ self.set_userinfo(userinfo)
199
+ self.set_host(host)
200
+ self.set_port(port)
201
+ self.set_path(path)
202
+ self.query = query
203
+ self.set_opaque(opaque)
204
+ self.fragment=(fragment)
205
+ end
206
+ if registry
207
+ raise InvalidURIError,
208
+ "the scheme #{@scheme} does not accept registry part: #{registry} (or bad hostname?)"
209
+ end
210
+
211
+ @scheme&.freeze
212
+ self.set_path('') if !@path && !@opaque # (see RFC2396 Section 5.2)
213
+ self.set_port(self.default_port) if self.default_port && !@port
214
+ end
215
+
216
+ #
217
+ # Returns the scheme component of the Bundler::URI.
218
+ #
219
+ # Bundler::URI("http://foo/bar/baz").scheme #=> "http"
220
+ #
221
+ attr_reader :scheme
222
+
223
+ # Returns the host component of the Bundler::URI.
224
+ #
225
+ # Bundler::URI("http://foo/bar/baz").host #=> "foo"
226
+ #
227
+ # It returns nil if no host component exists.
228
+ #
229
+ # Bundler::URI("mailto:foo@example.org").host #=> nil
230
+ #
231
+ # The component does not contain the port number.
232
+ #
233
+ # Bundler::URI("http://foo:8080/bar/baz").host #=> "foo"
234
+ #
235
+ # Since IPv6 addresses are wrapped with brackets in URIs,
236
+ # this method returns IPv6 addresses wrapped with brackets.
237
+ # This form is not appropriate to pass to socket methods such as TCPSocket.open.
238
+ # If unwrapped host names are required, use the #hostname method.
239
+ #
240
+ # Bundler::URI("http://[::1]/bar/baz").host #=> "[::1]"
241
+ # Bundler::URI("http://[::1]/bar/baz").hostname #=> "::1"
242
+ #
243
+ attr_reader :host
244
+
245
+ # Returns the port component of the Bundler::URI.
246
+ #
247
+ # Bundler::URI("http://foo/bar/baz").port #=> 80
248
+ # Bundler::URI("http://foo:8080/bar/baz").port #=> 8080
249
+ #
250
+ attr_reader :port
251
+
252
+ def registry # :nodoc:
253
+ nil
254
+ end
255
+
256
+ # Returns the path component of the Bundler::URI.
257
+ #
258
+ # Bundler::URI("http://foo/bar/baz").path #=> "/bar/baz"
259
+ #
260
+ attr_reader :path
261
+
262
+ # Returns the query component of the Bundler::URI.
263
+ #
264
+ # Bundler::URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
265
+ #
266
+ attr_reader :query
267
+
268
+ # Returns the opaque part of the Bundler::URI.
269
+ #
270
+ # Bundler::URI("mailto:foo@example.org").opaque #=> "foo@example.org"
271
+ # Bundler::URI("http://foo/bar/baz").opaque #=> nil
272
+ #
273
+ # The portion of the path that does not make use of the slash '/'.
274
+ # The path typically refers to an absolute path or an opaque part.
275
+ # (See RFC2396 Section 3 and 5.2.)
276
+ #
277
+ attr_reader :opaque
278
+
279
+ # Returns the fragment component of the Bundler::URI.
280
+ #
281
+ # Bundler::URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
282
+ #
283
+ attr_reader :fragment
284
+
285
+ # Returns the parser to be used.
286
+ #
287
+ # Unless a Bundler::URI::Parser is defined, DEFAULT_PARSER is used.
288
+ #
289
+ def parser
290
+ if !defined?(@parser) || !@parser
291
+ DEFAULT_PARSER
292
+ else
293
+ @parser || DEFAULT_PARSER
294
+ end
295
+ end
296
+
297
+ # Replaces self by other Bundler::URI object.
298
+ #
299
+ def replace!(oth)
300
+ if self.class != oth.class
301
+ raise ArgumentError, "expected #{self.class} object"
302
+ end
303
+
304
+ component.each do |c|
305
+ self.__send__("#{c}=", oth.__send__(c))
306
+ end
307
+ end
308
+ private :replace!
309
+
310
+ #
311
+ # Components of the Bundler::URI in the order.
312
+ #
313
+ def component
314
+ self.class.component
315
+ end
316
+
317
+ #
318
+ # Checks the scheme +v+ component against the Bundler::URI::Parser Regexp for :SCHEME.
319
+ #
320
+ def check_scheme(v)
321
+ if v && parser.regexp[:SCHEME] !~ v
322
+ raise InvalidComponentError,
323
+ "bad component(expected scheme component): #{v}"
324
+ end
325
+
326
+ return true
327
+ end
328
+ private :check_scheme
329
+
330
+ # Protected setter for the scheme component +v+.
331
+ #
332
+ # See also Bundler::URI::Generic.scheme=.
333
+ #
334
+ def set_scheme(v)
335
+ @scheme = v&.downcase
336
+ end
337
+ protected :set_scheme
338
+
339
+ #
340
+ # == Args
341
+ #
342
+ # +v+::
343
+ # String
344
+ #
345
+ # == Description
346
+ #
347
+ # Public setter for the scheme component +v+
348
+ # (with validation).
349
+ #
350
+ # See also Bundler::URI::Generic.check_scheme.
351
+ #
352
+ # == Usage
353
+ #
354
+ # require 'bundler/vendor/uri/lib/uri'
355
+ #
356
+ # uri = Bundler::URI.parse("http://my.example.com")
357
+ # uri.scheme = "https"
358
+ # uri.to_s #=> "https://my.example.com"
359
+ #
360
+ def scheme=(v)
361
+ check_scheme(v)
362
+ set_scheme(v)
363
+ v
364
+ end
365
+
366
+ #
367
+ # Checks the +user+ and +password+.
368
+ #
369
+ # If +password+ is not provided, then +user+ is
370
+ # split, using Bundler::URI::Generic.split_userinfo, to
371
+ # pull +user+ and +password.
372
+ #
373
+ # See also Bundler::URI::Generic.check_user, Bundler::URI::Generic.check_password.
374
+ #
375
+ def check_userinfo(user, password = nil)
376
+ if !password
377
+ user, password = split_userinfo(user)
378
+ end
379
+ check_user(user)
380
+ check_password(password, user)
381
+
382
+ return true
383
+ end
384
+ private :check_userinfo
385
+
386
+ #
387
+ # Checks the user +v+ component for RFC2396 compliance
388
+ # and against the Bundler::URI::Parser Regexp for :USERINFO.
389
+ #
390
+ # Can not have a registry or opaque component defined,
391
+ # with a user component defined.
392
+ #
393
+ def check_user(v)
394
+ if @opaque
395
+ raise InvalidURIError,
396
+ "cannot set user with opaque"
397
+ end
398
+
399
+ return v unless v
400
+
401
+ if parser.regexp[:USERINFO] !~ v
402
+ raise InvalidComponentError,
403
+ "bad component(expected userinfo component or user component): #{v}"
404
+ end
405
+
406
+ return true
407
+ end
408
+ private :check_user
409
+
410
+ #
411
+ # Checks the password +v+ component for RFC2396 compliance
412
+ # and against the Bundler::URI::Parser Regexp for :USERINFO.
413
+ #
414
+ # Can not have a registry or opaque component defined,
415
+ # with a user component defined.
416
+ #
417
+ def check_password(v, user = @user)
418
+ if @opaque
419
+ raise InvalidURIError,
420
+ "cannot set password with opaque"
421
+ end
422
+ return v unless v
423
+
424
+ if !user
425
+ raise InvalidURIError,
426
+ "password component depends user component"
427
+ end
428
+
429
+ if parser.regexp[:USERINFO] !~ v
430
+ raise InvalidComponentError,
431
+ "bad password component"
432
+ end
433
+
434
+ return true
435
+ end
436
+ private :check_password
437
+
438
+ #
439
+ # Sets userinfo, argument is string like 'name:pass'.
440
+ #
441
+ def userinfo=(userinfo)
442
+ if userinfo.nil?
443
+ return nil
444
+ end
445
+ check_userinfo(*userinfo)
446
+ set_userinfo(*userinfo)
447
+ # returns userinfo
448
+ end
449
+
450
+ #
451
+ # == Args
452
+ #
453
+ # +v+::
454
+ # String
455
+ #
456
+ # == Description
457
+ #
458
+ # Public setter for the +user+ component
459
+ # (with validation).
460
+ #
461
+ # See also Bundler::URI::Generic.check_user.
462
+ #
463
+ # == Usage
464
+ #
465
+ # require 'bundler/vendor/uri/lib/uri'
466
+ #
467
+ # uri = Bundler::URI.parse("http://john:S3nsit1ve@my.example.com")
468
+ # uri.user = "sam"
469
+ # uri.to_s #=> "http://sam:V3ry_S3nsit1ve@my.example.com"
470
+ #
471
+ def user=(user)
472
+ check_user(user)
473
+ set_user(user)
474
+ # returns user
475
+ end
476
+
477
+ #
478
+ # == Args
479
+ #
480
+ # +v+::
481
+ # String
482
+ #
483
+ # == Description
484
+ #
485
+ # Public setter for the +password+ component
486
+ # (with validation).
487
+ #
488
+ # See also Bundler::URI::Generic.check_password.
489
+ #
490
+ # == Usage
491
+ #
492
+ # require 'bundler/vendor/uri/lib/uri'
493
+ #
494
+ # uri = Bundler::URI.parse("http://john:S3nsit1ve@my.example.com")
495
+ # uri.password = "V3ry_S3nsit1ve"
496
+ # uri.to_s #=> "http://john:V3ry_S3nsit1ve@my.example.com"
497
+ #
498
+ def password=(password)
499
+ check_password(password)
500
+ set_password(password)
501
+ # returns password
502
+ end
503
+
504
+ # Protected setter for the +user+ component, and +password+ if available
505
+ # (with validation).
506
+ #
507
+ # See also Bundler::URI::Generic.userinfo=.
508
+ #
509
+ def set_userinfo(user, password = nil)
510
+ unless password
511
+ user, password = split_userinfo(user)
512
+ end
513
+ @user = user
514
+ @password = password if password
515
+
516
+ [@user, @password]
517
+ end
518
+ protected :set_userinfo
519
+
520
+ # Protected setter for the user component +v+.
521
+ #
522
+ # See also Bundler::URI::Generic.user=.
523
+ #
524
+ def set_user(v)
525
+ set_userinfo(v, @password)
526
+ v
527
+ end
528
+ protected :set_user
529
+
530
+ # Protected setter for the password component +v+.
531
+ #
532
+ # See also Bundler::URI::Generic.password=.
533
+ #
534
+ def set_password(v)
535
+ @password = v
536
+ # returns v
537
+ end
538
+ protected :set_password
539
+
540
+ # Returns the userinfo +ui+ as <code>[user, password]</code>
541
+ # if properly formatted as 'user:password'.
542
+ def split_userinfo(ui)
543
+ return nil, nil unless ui
544
+ user, password = ui.split(':', 2)
545
+
546
+ return user, password
547
+ end
548
+ private :split_userinfo
549
+
550
+ # Escapes 'user:password' +v+ based on RFC 1738 section 3.1.
551
+ def escape_userpass(v)
552
+ parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
553
+ end
554
+ private :escape_userpass
555
+
556
+ # Returns the userinfo, either as 'user' or 'user:password'.
557
+ def userinfo
558
+ if @user.nil?
559
+ nil
560
+ elsif @password.nil?
561
+ @user
562
+ else
563
+ @user + ':' + @password
564
+ end
565
+ end
566
+
567
+ # Returns the user component (without Bundler::URI decoding).
568
+ def user
569
+ @user
570
+ end
571
+
572
+ # Returns the password component (without Bundler::URI decoding).
573
+ def password
574
+ @password
575
+ end
576
+
577
+ # Returns the user component after Bundler::URI decoding.
578
+ def decoded_user
579
+ Bundler::URI.decode_uri_component(@user) if @user
580
+ end
581
+
582
+ # Returns the password component after Bundler::URI decoding.
583
+ def decoded_password
584
+ Bundler::URI.decode_uri_component(@password) if @password
585
+ end
586
+
587
+ #
588
+ # Checks the host +v+ component for RFC2396 compliance
589
+ # and against the Bundler::URI::Parser Regexp for :HOST.
590
+ #
591
+ # Can not have a registry or opaque component defined,
592
+ # with a host component defined.
593
+ #
594
+ def check_host(v)
595
+ return v unless v
596
+
597
+ if @opaque
598
+ raise InvalidURIError,
599
+ "cannot set host with registry or opaque"
600
+ elsif parser.regexp[:HOST] !~ v
601
+ raise InvalidComponentError,
602
+ "bad component(expected host component): #{v}"
603
+ end
604
+
605
+ return true
606
+ end
607
+ private :check_host
608
+
609
+ # Protected setter for the host component +v+.
610
+ #
611
+ # See also Bundler::URI::Generic.host=.
612
+ #
613
+ def set_host(v)
614
+ @host = v
615
+ end
616
+ protected :set_host
617
+
618
+ #
619
+ # == Args
620
+ #
621
+ # +v+::
622
+ # String
623
+ #
624
+ # == Description
625
+ #
626
+ # Public setter for the host component +v+
627
+ # (with validation).
628
+ #
629
+ # See also Bundler::URI::Generic.check_host.
630
+ #
631
+ # == Usage
632
+ #
633
+ # require 'bundler/vendor/uri/lib/uri'
634
+ #
635
+ # uri = Bundler::URI.parse("http://my.example.com")
636
+ # uri.host = "foo.com"
637
+ # uri.to_s #=> "http://foo.com"
638
+ #
639
+ def host=(v)
640
+ check_host(v)
641
+ set_host(v)
642
+ v
643
+ end
644
+
645
+ # Extract the host part of the Bundler::URI and unwrap brackets for IPv6 addresses.
646
+ #
647
+ # This method is the same as Bundler::URI::Generic#host except
648
+ # brackets for IPv6 (and future IP) addresses are removed.
649
+ #
650
+ # uri = Bundler::URI("http://[::1]/bar")
651
+ # uri.hostname #=> "::1"
652
+ # uri.host #=> "[::1]"
653
+ #
654
+ def hostname
655
+ v = self.host
656
+ v&.start_with?('[') && v.end_with?(']') ? v[1..-2] : v
657
+ end
658
+
659
+ # Sets the host part of the Bundler::URI as the argument with brackets for IPv6 addresses.
660
+ #
661
+ # This method is the same as Bundler::URI::Generic#host= except
662
+ # the argument can be a bare IPv6 address.
663
+ #
664
+ # uri = Bundler::URI("http://foo/bar")
665
+ # uri.hostname = "::1"
666
+ # uri.to_s #=> "http://[::1]/bar"
667
+ #
668
+ # If the argument seems to be an IPv6 address,
669
+ # it is wrapped with brackets.
670
+ #
671
+ def hostname=(v)
672
+ v = "[#{v}]" if !(v&.start_with?('[') && v&.end_with?(']')) && v&.index(':')
673
+ self.host = v
674
+ end
675
+
676
+ #
677
+ # Checks the port +v+ component for RFC2396 compliance
678
+ # and against the Bundler::URI::Parser Regexp for :PORT.
679
+ #
680
+ # Can not have a registry or opaque component defined,
681
+ # with a port component defined.
682
+ #
683
+ def check_port(v)
684
+ return v unless v
685
+
686
+ if @opaque
687
+ raise InvalidURIError,
688
+ "cannot set port with registry or opaque"
689
+ elsif !v.kind_of?(Integer) && parser.regexp[:PORT] !~ v
690
+ raise InvalidComponentError,
691
+ "bad component(expected port component): #{v.inspect}"
692
+ end
693
+
694
+ return true
695
+ end
696
+ private :check_port
697
+
698
+ # Protected setter for the port component +v+.
699
+ #
700
+ # See also Bundler::URI::Generic.port=.
701
+ #
702
+ def set_port(v)
703
+ v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Integer)
704
+ @port = v
705
+ end
706
+ protected :set_port
707
+
708
+ #
709
+ # == Args
710
+ #
711
+ # +v+::
712
+ # String
713
+ #
714
+ # == Description
715
+ #
716
+ # Public setter for the port component +v+
717
+ # (with validation).
718
+ #
719
+ # See also Bundler::URI::Generic.check_port.
720
+ #
721
+ # == Usage
722
+ #
723
+ # require 'bundler/vendor/uri/lib/uri'
724
+ #
725
+ # uri = Bundler::URI.parse("http://my.example.com")
726
+ # uri.port = 8080
727
+ # uri.to_s #=> "http://my.example.com:8080"
728
+ #
729
+ def port=(v)
730
+ check_port(v)
731
+ set_port(v)
732
+ port
733
+ end
734
+
735
+ def check_registry(v) # :nodoc:
736
+ raise InvalidURIError, "cannot set registry"
737
+ end
738
+ private :check_registry
739
+
740
+ def set_registry(v) #:nodoc:
741
+ raise InvalidURIError, "cannot set registry"
742
+ end
743
+ protected :set_registry
744
+
745
+ def registry=(v)
746
+ raise InvalidURIError, "cannot set registry"
747
+ end
748
+
749
+ #
750
+ # Checks the path +v+ component for RFC2396 compliance
751
+ # and against the Bundler::URI::Parser Regexp
752
+ # for :ABS_PATH and :REL_PATH.
753
+ #
754
+ # Can not have a opaque component defined,
755
+ # with a path component defined.
756
+ #
757
+ def check_path(v)
758
+ # raise if both hier and opaque are not nil, because:
759
+ # absoluteURI = scheme ":" ( hier_part | opaque_part )
760
+ # hier_part = ( net_path | abs_path ) [ "?" query ]
761
+ if v && @opaque
762
+ raise InvalidURIError,
763
+ "path conflicts with opaque"
764
+ end
765
+
766
+ # If scheme is ftp, path may be relative.
767
+ # See RFC 1738 section 3.2.2, and RFC 2396.
768
+ if @scheme && @scheme != "ftp"
769
+ if v && v != '' && parser.regexp[:ABS_PATH] !~ v
770
+ raise InvalidComponentError,
771
+ "bad component(expected absolute path component): #{v}"
772
+ end
773
+ else
774
+ if v && v != '' && parser.regexp[:ABS_PATH] !~ v &&
775
+ parser.regexp[:REL_PATH] !~ v
776
+ raise InvalidComponentError,
777
+ "bad component(expected relative path component): #{v}"
778
+ end
779
+ end
780
+
781
+ return true
782
+ end
783
+ private :check_path
784
+
785
+ # Protected setter for the path component +v+.
786
+ #
787
+ # See also Bundler::URI::Generic.path=.
788
+ #
789
+ def set_path(v)
790
+ @path = v
791
+ end
792
+ protected :set_path
793
+
794
+ #
795
+ # == Args
796
+ #
797
+ # +v+::
798
+ # String
799
+ #
800
+ # == Description
801
+ #
802
+ # Public setter for the path component +v+
803
+ # (with validation).
804
+ #
805
+ # See also Bundler::URI::Generic.check_path.
806
+ #
807
+ # == Usage
808
+ #
809
+ # require 'bundler/vendor/uri/lib/uri'
810
+ #
811
+ # uri = Bundler::URI.parse("http://my.example.com/pub/files")
812
+ # uri.path = "/faq/"
813
+ # uri.to_s #=> "http://my.example.com/faq/"
814
+ #
815
+ def path=(v)
816
+ check_path(v)
817
+ set_path(v)
818
+ v
819
+ end
820
+
821
+ #
822
+ # == Args
823
+ #
824
+ # +v+::
825
+ # String
826
+ #
827
+ # == Description
828
+ #
829
+ # Public setter for the query component +v+.
830
+ #
831
+ # == Usage
832
+ #
833
+ # require 'bundler/vendor/uri/lib/uri'
834
+ #
835
+ # uri = Bundler::URI.parse("http://my.example.com/?id=25")
836
+ # uri.query = "id=1"
837
+ # uri.to_s #=> "http://my.example.com/?id=1"
838
+ #
839
+ def query=(v)
840
+ return @query = nil unless v
841
+ raise InvalidURIError, "query conflicts with opaque" if @opaque
842
+
843
+ x = v.to_str
844
+ v = x.dup if x.equal? v
845
+ v.encode!(Encoding::UTF_8) rescue nil
846
+ v.delete!("\t\r\n")
847
+ v.force_encoding(Encoding::ASCII_8BIT)
848
+ raise InvalidURIError, "invalid percent escape: #{$1}" if /(%\H\H)/n.match(v)
849
+ v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X' % $&.ord}
850
+ v.force_encoding(Encoding::US_ASCII)
851
+ @query = v
852
+ end
853
+
854
+ #
855
+ # Checks the opaque +v+ component for RFC2396 compliance and
856
+ # against the Bundler::URI::Parser Regexp for :OPAQUE.
857
+ #
858
+ # Can not have a host, port, user, or path component defined,
859
+ # with an opaque component defined.
860
+ #
861
+ def check_opaque(v)
862
+ return v unless v
863
+
864
+ # raise if both hier and opaque are not nil, because:
865
+ # absoluteURI = scheme ":" ( hier_part | opaque_part )
866
+ # hier_part = ( net_path | abs_path ) [ "?" query ]
867
+ if @host || @port || @user || @path # userinfo = @user + ':' + @password
868
+ raise InvalidURIError,
869
+ "cannot set opaque with host, port, userinfo or path"
870
+ elsif v && parser.regexp[:OPAQUE] !~ v
871
+ raise InvalidComponentError,
872
+ "bad component(expected opaque component): #{v}"
873
+ end
874
+
875
+ return true
876
+ end
877
+ private :check_opaque
878
+
879
+ # Protected setter for the opaque component +v+.
880
+ #
881
+ # See also Bundler::URI::Generic.opaque=.
882
+ #
883
+ def set_opaque(v)
884
+ @opaque = v
885
+ end
886
+ protected :set_opaque
887
+
888
+ #
889
+ # == Args
890
+ #
891
+ # +v+::
892
+ # String
893
+ #
894
+ # == Description
895
+ #
896
+ # Public setter for the opaque component +v+
897
+ # (with validation).
898
+ #
899
+ # See also Bundler::URI::Generic.check_opaque.
900
+ #
901
+ def opaque=(v)
902
+ check_opaque(v)
903
+ set_opaque(v)
904
+ v
905
+ end
906
+
907
+ #
908
+ # Checks the fragment +v+ component against the Bundler::URI::Parser Regexp for :FRAGMENT.
909
+ #
910
+ #
911
+ # == Args
912
+ #
913
+ # +v+::
914
+ # String
915
+ #
916
+ # == Description
917
+ #
918
+ # Public setter for the fragment component +v+
919
+ # (with validation).
920
+ #
921
+ # == Usage
922
+ #
923
+ # require 'bundler/vendor/uri/lib/uri'
924
+ #
925
+ # uri = Bundler::URI.parse("http://my.example.com/?id=25#time=1305212049")
926
+ # uri.fragment = "time=1305212086"
927
+ # uri.to_s #=> "http://my.example.com/?id=25#time=1305212086"
928
+ #
929
+ def fragment=(v)
930
+ return @fragment = nil unless v
931
+
932
+ x = v.to_str
933
+ v = x.dup if x.equal? v
934
+ v.encode!(Encoding::UTF_8) rescue nil
935
+ v.delete!("\t\r\n")
936
+ v.force_encoding(Encoding::ASCII_8BIT)
937
+ v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord}
938
+ v.force_encoding(Encoding::US_ASCII)
939
+ @fragment = v
940
+ end
941
+
942
+ #
943
+ # Returns true if Bundler::URI is hierarchical.
944
+ #
945
+ # == Description
946
+ #
947
+ # Bundler::URI has components listed in order of decreasing significance from left to right,
948
+ # see RFC3986 https://www.rfc-editor.org/rfc/rfc3986 1.2.3.
949
+ #
950
+ # == Usage
951
+ #
952
+ # require 'bundler/vendor/uri/lib/uri'
953
+ #
954
+ # uri = Bundler::URI.parse("http://my.example.com/")
955
+ # uri.hierarchical?
956
+ # #=> true
957
+ # uri = Bundler::URI.parse("mailto:joe@example.com")
958
+ # uri.hierarchical?
959
+ # #=> false
960
+ #
961
+ def hierarchical?
962
+ if @path
963
+ true
964
+ else
965
+ false
966
+ end
967
+ end
968
+
969
+ #
970
+ # Returns true if Bundler::URI has a scheme (e.g. http:// or https://) specified.
971
+ #
972
+ def absolute?
973
+ if @scheme
974
+ true
975
+ else
976
+ false
977
+ end
978
+ end
979
+ alias absolute absolute?
980
+
981
+ #
982
+ # Returns true if Bundler::URI does not have a scheme (e.g. http:// or https://) specified.
983
+ #
984
+ def relative?
985
+ !absolute?
986
+ end
987
+
988
+ #
989
+ # Returns an Array of the path split on '/'.
990
+ #
991
+ def split_path(path)
992
+ path.split("/", -1)
993
+ end
994
+ private :split_path
995
+
996
+ #
997
+ # Merges a base path +base+, with relative path +rel+,
998
+ # returns a modified base path.
999
+ #
1000
+ def merge_path(base, rel)
1001
+
1002
+ # RFC2396, Section 5.2, 5)
1003
+ # RFC2396, Section 5.2, 6)
1004
+ base_path = split_path(base)
1005
+ rel_path = split_path(rel)
1006
+
1007
+ # RFC2396, Section 5.2, 6), a)
1008
+ base_path << '' if base_path.last == '..'
1009
+ while i = base_path.index('..')
1010
+ base_path.slice!(i - 1, 2)
1011
+ end
1012
+
1013
+ if (first = rel_path.first) and first.empty?
1014
+ base_path.clear
1015
+ rel_path.shift
1016
+ end
1017
+
1018
+ # RFC2396, Section 5.2, 6), c)
1019
+ # RFC2396, Section 5.2, 6), d)
1020
+ rel_path.push('') if rel_path.last == '.' || rel_path.last == '..'
1021
+ rel_path.delete('.')
1022
+
1023
+ # RFC2396, Section 5.2, 6), e)
1024
+ tmp = []
1025
+ rel_path.each do |x|
1026
+ if x == '..' &&
1027
+ !(tmp.empty? || tmp.last == '..')
1028
+ tmp.pop
1029
+ else
1030
+ tmp << x
1031
+ end
1032
+ end
1033
+
1034
+ add_trailer_slash = !tmp.empty?
1035
+ if base_path.empty?
1036
+ base_path = [''] # keep '/' for root directory
1037
+ elsif add_trailer_slash
1038
+ base_path.pop
1039
+ end
1040
+ while x = tmp.shift
1041
+ if x == '..'
1042
+ # RFC2396, Section 4
1043
+ # a .. or . in an absolute path has no special meaning
1044
+ base_path.pop if base_path.size > 1
1045
+ else
1046
+ # if x == '..'
1047
+ # valid absolute (but abnormal) path "/../..."
1048
+ # else
1049
+ # valid absolute path
1050
+ # end
1051
+ base_path << x
1052
+ tmp.each {|t| base_path << t}
1053
+ add_trailer_slash = false
1054
+ break
1055
+ end
1056
+ end
1057
+ base_path.push('') if add_trailer_slash
1058
+
1059
+ return base_path.join('/')
1060
+ end
1061
+ private :merge_path
1062
+
1063
+ #
1064
+ # == Args
1065
+ #
1066
+ # +oth+::
1067
+ # Bundler::URI or String
1068
+ #
1069
+ # == Description
1070
+ #
1071
+ # Destructive form of #merge.
1072
+ #
1073
+ # == Usage
1074
+ #
1075
+ # require 'bundler/vendor/uri/lib/uri'
1076
+ #
1077
+ # uri = Bundler::URI.parse("http://my.example.com")
1078
+ # uri.merge!("/main.rbx?page=1")
1079
+ # uri.to_s # => "http://my.example.com/main.rbx?page=1"
1080
+ #
1081
+ def merge!(oth)
1082
+ t = merge(oth)
1083
+ if self == t
1084
+ nil
1085
+ else
1086
+ replace!(t)
1087
+ self
1088
+ end
1089
+ end
1090
+
1091
+ #
1092
+ # == Args
1093
+ #
1094
+ # +oth+::
1095
+ # Bundler::URI or String
1096
+ #
1097
+ # == Description
1098
+ #
1099
+ # Merges two URIs.
1100
+ #
1101
+ # == Usage
1102
+ #
1103
+ # require 'bundler/vendor/uri/lib/uri'
1104
+ #
1105
+ # uri = Bundler::URI.parse("http://my.example.com")
1106
+ # uri.merge("/main.rbx?page=1")
1107
+ # # => "http://my.example.com/main.rbx?page=1"
1108
+ #
1109
+ def merge(oth)
1110
+ rel = parser.__send__(:convert_to_uri, oth)
1111
+
1112
+ if rel.absolute?
1113
+ #raise BadURIError, "both Bundler::URI are absolute" if absolute?
1114
+ # hmm... should return oth for usability?
1115
+ return rel
1116
+ end
1117
+
1118
+ unless self.absolute?
1119
+ raise BadURIError, "both Bundler::URI are relative"
1120
+ end
1121
+
1122
+ base = self.dup
1123
+
1124
+ authority = rel.userinfo || rel.host || rel.port
1125
+
1126
+ # RFC2396, Section 5.2, 2)
1127
+ if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
1128
+ base.fragment=(rel.fragment) if rel.fragment
1129
+ return base
1130
+ end
1131
+
1132
+ base.query = nil
1133
+ base.fragment=(nil)
1134
+
1135
+ # RFC2396, Section 5.2, 4)
1136
+ if !authority
1137
+ base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
1138
+ else
1139
+ # RFC2396, Section 5.2, 4)
1140
+ base.set_path(rel.path) if rel.path
1141
+ end
1142
+
1143
+ # RFC2396, Section 5.2, 7)
1144
+ base.set_userinfo(rel.userinfo) if rel.userinfo
1145
+ base.set_host(rel.host) if rel.host
1146
+ base.set_port(rel.port) if rel.port
1147
+ base.query = rel.query if rel.query
1148
+ base.fragment=(rel.fragment) if rel.fragment
1149
+
1150
+ return base
1151
+ end # merge
1152
+ alias + merge
1153
+
1154
+ # :stopdoc:
1155
+ def route_from_path(src, dst)
1156
+ case dst
1157
+ when src
1158
+ # RFC2396, Section 4.2
1159
+ return ''
1160
+ when %r{(?:\A|/)\.\.?(?:/|\z)}
1161
+ # dst has abnormal absolute path,
1162
+ # like "/./", "/../", "/x/../", ...
1163
+ return dst.dup
1164
+ end
1165
+
1166
+ src_path = src.scan(%r{[^/]*/})
1167
+ dst_path = dst.scan(%r{[^/]*/?})
1168
+
1169
+ # discard same parts
1170
+ while !dst_path.empty? && dst_path.first == src_path.first
1171
+ src_path.shift
1172
+ dst_path.shift
1173
+ end
1174
+
1175
+ tmp = dst_path.join
1176
+
1177
+ # calculate
1178
+ if src_path.empty?
1179
+ if tmp.empty?
1180
+ return './'
1181
+ elsif dst_path.first.include?(':') # (see RFC2396 Section 5)
1182
+ return './' + tmp
1183
+ else
1184
+ return tmp
1185
+ end
1186
+ end
1187
+
1188
+ return '../' * src_path.size + tmp
1189
+ end
1190
+ private :route_from_path
1191
+ # :startdoc:
1192
+
1193
+ # :stopdoc:
1194
+ def route_from0(oth)
1195
+ oth = parser.__send__(:convert_to_uri, oth)
1196
+ if self.relative?
1197
+ raise BadURIError,
1198
+ "relative Bundler::URI: #{self}"
1199
+ end
1200
+ if oth.relative?
1201
+ raise BadURIError,
1202
+ "relative Bundler::URI: #{oth}"
1203
+ end
1204
+
1205
+ if self.scheme != oth.scheme
1206
+ return self, self.dup
1207
+ end
1208
+ rel = Bundler::URI::Generic.new(nil, # it is relative Bundler::URI
1209
+ self.userinfo, self.host, self.port,
1210
+ nil, self.path, self.opaque,
1211
+ self.query, self.fragment, parser)
1212
+
1213
+ if rel.userinfo != oth.userinfo ||
1214
+ rel.host.to_s.downcase != oth.host.to_s.downcase ||
1215
+ rel.port != oth.port
1216
+
1217
+ if self.userinfo.nil? && self.host.nil?
1218
+ return self, self.dup
1219
+ end
1220
+
1221
+ rel.set_port(nil) if rel.port == oth.default_port
1222
+ return rel, rel
1223
+ end
1224
+ rel.set_userinfo(nil)
1225
+ rel.set_host(nil)
1226
+ rel.set_port(nil)
1227
+
1228
+ if rel.path && rel.path == oth.path
1229
+ rel.set_path('')
1230
+ rel.query = nil if rel.query == oth.query
1231
+ return rel, rel
1232
+ elsif rel.opaque && rel.opaque == oth.opaque
1233
+ rel.set_opaque('')
1234
+ rel.query = nil if rel.query == oth.query
1235
+ return rel, rel
1236
+ end
1237
+
1238
+ # you can modify `rel', but cannot `oth'.
1239
+ return oth, rel
1240
+ end
1241
+ private :route_from0
1242
+ # :startdoc:
1243
+
1244
+ #
1245
+ # == Args
1246
+ #
1247
+ # +oth+::
1248
+ # Bundler::URI or String
1249
+ #
1250
+ # == Description
1251
+ #
1252
+ # Calculates relative path from oth to self.
1253
+ #
1254
+ # == Usage
1255
+ #
1256
+ # require 'bundler/vendor/uri/lib/uri'
1257
+ #
1258
+ # uri = Bundler::URI.parse('http://my.example.com/main.rbx?page=1')
1259
+ # uri.route_from('http://my.example.com')
1260
+ # #=> #<Bundler::URI::Generic /main.rbx?page=1>
1261
+ #
1262
+ def route_from(oth)
1263
+ # you can modify `rel', but cannot `oth'.
1264
+ begin
1265
+ oth, rel = route_from0(oth)
1266
+ rescue
1267
+ raise $!.class, $!.message
1268
+ end
1269
+ if oth == rel
1270
+ return rel
1271
+ end
1272
+
1273
+ rel.set_path(route_from_path(oth.path, self.path))
1274
+ if rel.path == './' && self.query
1275
+ # "./?foo" -> "?foo"
1276
+ rel.set_path('')
1277
+ end
1278
+
1279
+ return rel
1280
+ end
1281
+
1282
+ alias - route_from
1283
+
1284
+ #
1285
+ # == Args
1286
+ #
1287
+ # +oth+::
1288
+ # Bundler::URI or String
1289
+ #
1290
+ # == Description
1291
+ #
1292
+ # Calculates relative path to oth from self.
1293
+ #
1294
+ # == Usage
1295
+ #
1296
+ # require 'bundler/vendor/uri/lib/uri'
1297
+ #
1298
+ # uri = Bundler::URI.parse('http://my.example.com')
1299
+ # uri.route_to('http://my.example.com/main.rbx?page=1')
1300
+ # #=> #<Bundler::URI::Generic /main.rbx?page=1>
1301
+ #
1302
+ def route_to(oth)
1303
+ parser.__send__(:convert_to_uri, oth).route_from(self)
1304
+ end
1305
+
1306
+ #
1307
+ # Returns normalized Bundler::URI.
1308
+ #
1309
+ # require 'bundler/vendor/uri/lib/uri'
1310
+ #
1311
+ # Bundler::URI("HTTP://my.EXAMPLE.com").normalize
1312
+ # #=> #<Bundler::URI::HTTP http://my.example.com/>
1313
+ #
1314
+ # Normalization here means:
1315
+ #
1316
+ # * scheme and host are converted to lowercase,
1317
+ # * an empty path component is set to "/".
1318
+ #
1319
+ def normalize
1320
+ uri = dup
1321
+ uri.normalize!
1322
+ uri
1323
+ end
1324
+
1325
+ #
1326
+ # Destructive version of #normalize.
1327
+ #
1328
+ def normalize!
1329
+ if path&.empty?
1330
+ set_path('/')
1331
+ end
1332
+ if scheme && scheme != scheme.downcase
1333
+ set_scheme(self.scheme.downcase)
1334
+ end
1335
+ if host && host != host.downcase
1336
+ set_host(self.host.downcase)
1337
+ end
1338
+ end
1339
+
1340
+ #
1341
+ # Constructs String from Bundler::URI.
1342
+ #
1343
+ def to_s
1344
+ str = ''.dup
1345
+ if @scheme
1346
+ str << @scheme
1347
+ str << ':'
1348
+ end
1349
+
1350
+ if @opaque
1351
+ str << @opaque
1352
+ else
1353
+ if @host || %w[file postgres].include?(@scheme)
1354
+ str << '//'
1355
+ end
1356
+ if self.userinfo
1357
+ str << self.userinfo
1358
+ str << '@'
1359
+ end
1360
+ if @host
1361
+ str << @host
1362
+ end
1363
+ if @port && @port != self.default_port
1364
+ str << ':'
1365
+ str << @port.to_s
1366
+ end
1367
+ if (@host || @port) && !@path.empty? && !@path.start_with?('/')
1368
+ str << '/'
1369
+ end
1370
+ str << @path
1371
+ if @query
1372
+ str << '?'
1373
+ str << @query
1374
+ end
1375
+ end
1376
+ if @fragment
1377
+ str << '#'
1378
+ str << @fragment
1379
+ end
1380
+ str
1381
+ end
1382
+ alias to_str to_s
1383
+
1384
+ #
1385
+ # Compares two URIs.
1386
+ #
1387
+ def ==(oth)
1388
+ if self.class == oth.class
1389
+ self.normalize.component_ary == oth.normalize.component_ary
1390
+ else
1391
+ false
1392
+ end
1393
+ end
1394
+
1395
+ def hash
1396
+ self.component_ary.hash
1397
+ end
1398
+
1399
+ def eql?(oth)
1400
+ self.class == oth.class &&
1401
+ parser == oth.parser &&
1402
+ self.component_ary.eql?(oth.component_ary)
1403
+ end
1404
+
1405
+ # Returns an Array of the components defined from the COMPONENT Array.
1406
+ def component_ary
1407
+ component.collect do |x|
1408
+ self.__send__(x)
1409
+ end
1410
+ end
1411
+ protected :component_ary
1412
+
1413
+ # == Args
1414
+ #
1415
+ # +components+::
1416
+ # Multiple Symbol arguments defined in Bundler::URI::HTTP.
1417
+ #
1418
+ # == Description
1419
+ #
1420
+ # Selects specified components from Bundler::URI.
1421
+ #
1422
+ # == Usage
1423
+ #
1424
+ # require 'bundler/vendor/uri/lib/uri'
1425
+ #
1426
+ # uri = Bundler::URI.parse('http://myuser:mypass@my.example.com/test.rbx')
1427
+ # uri.select(:userinfo, :host, :path)
1428
+ # # => ["myuser:mypass", "my.example.com", "/test.rbx"]
1429
+ #
1430
+ def select(*components)
1431
+ components.collect do |c|
1432
+ if component.include?(c)
1433
+ self.__send__(c)
1434
+ else
1435
+ raise ArgumentError,
1436
+ "expected of components of #{self.class} (#{self.class.component.join(', ')})"
1437
+ end
1438
+ end
1439
+ end
1440
+
1441
+ def inspect
1442
+ "#<#{self.class} #{self}>"
1443
+ end
1444
+
1445
+ #
1446
+ # == Args
1447
+ #
1448
+ # +v+::
1449
+ # Bundler::URI or String
1450
+ #
1451
+ # == Description
1452
+ #
1453
+ # Attempts to parse other Bundler::URI +oth+,
1454
+ # returns [parsed_oth, self].
1455
+ #
1456
+ # == Usage
1457
+ #
1458
+ # require 'bundler/vendor/uri/lib/uri'
1459
+ #
1460
+ # uri = Bundler::URI.parse("http://my.example.com")
1461
+ # uri.coerce("http://foo.com")
1462
+ # #=> [#<Bundler::URI::HTTP http://foo.com>, #<Bundler::URI::HTTP http://my.example.com>]
1463
+ #
1464
+ def coerce(oth)
1465
+ case oth
1466
+ when String
1467
+ oth = parser.parse(oth)
1468
+ else
1469
+ super
1470
+ end
1471
+
1472
+ return oth, self
1473
+ end
1474
+
1475
+ # Returns a proxy Bundler::URI.
1476
+ # The proxy Bundler::URI is obtained from environment variables such as http_proxy,
1477
+ # ftp_proxy, no_proxy, etc.
1478
+ # If there is no proper proxy, nil is returned.
1479
+ #
1480
+ # If the optional parameter +env+ is specified, it is used instead of ENV.
1481
+ #
1482
+ # Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.)
1483
+ # are examined, too.
1484
+ #
1485
+ # But http_proxy and HTTP_PROXY is treated specially under CGI environment.
1486
+ # It's because HTTP_PROXY may be set by Proxy: header.
1487
+ # So HTTP_PROXY is not used.
1488
+ # http_proxy is not used too if the variable is case insensitive.
1489
+ # CGI_HTTP_PROXY can be used instead.
1490
+ def find_proxy(env=ENV)
1491
+ raise BadURIError, "relative Bundler::URI: #{self}" if self.relative?
1492
+ name = self.scheme.downcase + '_proxy'
1493
+ proxy_uri = nil
1494
+ if name == 'http_proxy' && env.include?('REQUEST_METHOD') # CGI?
1495
+ # HTTP_PROXY conflicts with *_proxy for proxy settings and
1496
+ # HTTP_* for header information in CGI.
1497
+ # So it should be careful to use it.
1498
+ pairs = env.reject {|k, v| /\Ahttp_proxy\z/i !~ k }
1499
+ case pairs.length
1500
+ when 0 # no proxy setting anyway.
1501
+ proxy_uri = nil
1502
+ when 1
1503
+ k, _ = pairs.shift
1504
+ if k == 'http_proxy' && env[k.upcase] == nil
1505
+ # http_proxy is safe to use because ENV is case sensitive.
1506
+ proxy_uri = env[name]
1507
+ else
1508
+ proxy_uri = nil
1509
+ end
1510
+ else # http_proxy is safe to use because ENV is case sensitive.
1511
+ proxy_uri = env.to_hash[name]
1512
+ end
1513
+ if !proxy_uri
1514
+ # Use CGI_HTTP_PROXY. cf. libwww-perl.
1515
+ proxy_uri = env["CGI_#{name.upcase}"]
1516
+ end
1517
+ elsif name == 'http_proxy'
1518
+ if RUBY_ENGINE == 'jruby' && p_addr = ENV_JAVA['http.proxyHost']
1519
+ p_port = ENV_JAVA['http.proxyPort']
1520
+ if p_user = ENV_JAVA['http.proxyUser']
1521
+ p_pass = ENV_JAVA['http.proxyPass']
1522
+ proxy_uri = "http://#{p_user}:#{p_pass}@#{p_addr}:#{p_port}"
1523
+ else
1524
+ proxy_uri = "http://#{p_addr}:#{p_port}"
1525
+ end
1526
+ else
1527
+ unless proxy_uri = env[name]
1528
+ if proxy_uri = env[name.upcase]
1529
+ warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.', uplevel: 1
1530
+ end
1531
+ end
1532
+ end
1533
+ else
1534
+ proxy_uri = env[name] || env[name.upcase]
1535
+ end
1536
+
1537
+ if proxy_uri.nil? || proxy_uri.empty?
1538
+ return nil
1539
+ end
1540
+
1541
+ if self.hostname
1542
+ begin
1543
+ addr = IPSocket.getaddress(self.hostname)
1544
+ return nil if /\A127\.|\A::1\z/ =~ addr
1545
+ rescue SocketError
1546
+ end
1547
+ end
1548
+
1549
+ name = 'no_proxy'
1550
+ if no_proxy = env[name] || env[name.upcase]
1551
+ return nil unless Bundler::URI::Generic.use_proxy?(self.hostname, addr, self.port, no_proxy)
1552
+ end
1553
+ Bundler::URI.parse(proxy_uri)
1554
+ end
1555
+
1556
+ def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc:
1557
+ hostname = hostname.downcase
1558
+ dothostname = ".#{hostname}"
1559
+ no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port|
1560
+ if !p_port || port == p_port.to_i
1561
+ if p_host.start_with?('.')
1562
+ return false if hostname.end_with?(p_host.downcase)
1563
+ else
1564
+ return false if dothostname.end_with?(".#{p_host.downcase}")
1565
+ end
1566
+ if addr
1567
+ begin
1568
+ return false if IPAddr.new(p_host).include?(addr)
1569
+ rescue IPAddr::InvalidAddressError
1570
+ next
1571
+ end
1572
+ end
1573
+ end
1574
+ }
1575
+ true
1576
+ end
1577
+ end
1578
+ end