Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Vendor uri library #7460

Merged
7 commits merged into from Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Rakefile
Expand Up @@ -268,6 +268,14 @@ else
sublib.prefix = "Bundler"
sublib.vendor_lib = "lib/bundler/vendor/connection_pool"
end

lib.dependency("uri") do |sublib|
sublib.version = "master"
sublib.download = { :github => "https://github.com/ruby/uri" }
sublib.namespace = "URI"
sublib.prefix = "Bundler"
sublib.vendor_lib = "lib/bundler/vendor/uri"
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli.rb
Expand Up @@ -784,7 +784,7 @@ def warn_on_outdated_bundler
return unless SharedHelpers.md5_available?

latest = Fetcher::CompactIndex.
new(nil, Source::Rubygems::Remote.new(URI("https://rubygems.org")), nil).
new(nil, Source::Rubygems::Remote.new(Bundler::URI("https://rubygems.org")), nil).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think all of these changes in lib are actually necessary because the Bundler::URI constant will beat URI anyways, but maybe they make it more explicit that we're using a vendored version of the uri gem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should replace vendored fileutils and uri to the minimum code like yaml_serializer in the next version.

But there is no enough time to release Bundler 2.1. We can try it Bundler 2.2 or Bundler 3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I agree and also started some work to be able to vendor only parts of libraries while still automating the process with automatiek 👍

send(:compact_index_client).
instance_variable_get(:@cache).
dependencies("bundler").
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/fetcher.rb
Expand Up @@ -97,7 +97,7 @@ def fetch_spec(spec)
spec -= [nil, "ruby", ""]
spec_file_name = "#{spec.join "-"}.gemspec"

uri = URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
uri = Bundler::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
if uri.scheme == "file"
path = Bundler.rubygems.correct_for_windows_path(uri.path)
Bundler.load_marshal Bundler.rubygems.inflate(Gem.read_binary(path))
Expand Down Expand Up @@ -244,7 +244,7 @@ def connection

con = PersistentHTTP.new :name => "bundler", :proxy => :ENV
if gem_proxy = Bundler.rubygems.configuration[:http_proxy]
con.proxy = URI.parse(gem_proxy) if gem_proxy != :no_proxy
con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy
end

if remote_uri.scheme == "https"
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/fetcher/downloader.rb
Expand Up @@ -21,7 +21,7 @@ def fetch(uri, headers = {}, counter = 0)
when Net::HTTPSuccess, Net::HTTPNotModified
response
when Net::HTTPRedirection
new_uri = URI.parse(response["location"])
new_uri = Bundler::URI.parse(response["location"])
if new_uri.host == uri.host
new_uri.user = uri.user
new_uri.password = uri.password
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/fetcher/index.rb
Expand Up @@ -28,7 +28,7 @@ def fetch_spec(spec)
spec -= [nil, "ruby", ""]
spec_file_name = "#{spec.join "-"}.gemspec"

uri = URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
uri = Bundler::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
if uri.scheme == "file"
path = Bundler.rubygems.correct_for_windows_path(uri.path)
Bundler.load_marshal Bundler.rubygems.inflate(Gem.read_binary(path))
Expand Down
1 change: 0 additions & 1 deletion lib/bundler/lazy_specification.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "uri"
require_relative "match_platform"

module Bundler
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/mirror.rb
Expand Up @@ -47,7 +47,7 @@ def parse(key, value)

def fetch_valid_mirror_for(uri)
downcased = uri.to_s.downcase
mirror = @mirrors[downcased] || @mirrors[URI(downcased).host] || Mirror.new(uri)
mirror = @mirrors[downcased] || @mirrors[Bundler::URI(downcased).host] || Mirror.new(uri)
mirror.validate!(@prober)
mirror = Mirror.new(uri) unless mirror.valid?
mirror
Expand All @@ -74,7 +74,7 @@ def uri=(uri)
@uri = if uri.nil?
nil
else
URI(uri.to_s)
Bundler::URI(uri.to_s)
end
@valid = nil
end
Expand Down Expand Up @@ -126,7 +126,7 @@ def initialize(config_line, value)
if uri == "all"
@all = true
else
@uri = URI(uri).absolute? ? Settings.normalize_uri(uri) : uri
@uri = Bundler::URI(uri).absolute? ? Settings.normalize_uri(uri) : uri
end
@value = value
end
Expand Down
6 changes: 2 additions & 4 deletions lib/bundler/plugin/api/source.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "uri"

module Bundler
module Plugin
class API
Expand Down Expand Up @@ -108,7 +106,7 @@ def post_install(spec, disable_exts = false)
def install_path
@install_path ||=
begin
base_name = File.basename(URI.parse(uri).normalize.path)
base_name = File.basename(Bundler::URI.parse(uri).normalize.path)

gem_install_dir.join("#{base_name}-#{uri_hash[0..11]}")
end
Expand Down Expand Up @@ -170,7 +168,7 @@ def unlock!
#
# This is used by `app_cache_path`
def app_cache_dirname
base_name = File.basename(URI.parse(uri).normalize.path)
base_name = File.basename(Bundler::URI.parse(uri).normalize.path)
"#{base_name}-#{uri_hash}"
end

Expand Down
2 changes: 0 additions & 2 deletions lib/bundler/remote_specification.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "uri"

module Bundler
# Represents a lazily loaded gem specification, where the full specification
# is on the source server in rubygems' "quick" index. The proxy object is to
Expand Down
11 changes: 7 additions & 4 deletions lib/bundler/settings.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "uri"

module Bundler
class Settings
autoload :Mirror, File.expand_path("mirror", __dir__)
Expand Down Expand Up @@ -152,7 +150,11 @@ def local_overrides
end

def mirror_for(uri)
uri = URI(uri.to_s) unless uri.is_a?(URI)
if uri.is_a?(String)
require_relative "vendored_uri"
uri = Bundler::URI(uri)
end

gem_mirrors.for(uri.to_s).uri
end

Expand Down Expand Up @@ -421,7 +423,8 @@ def self.normalize_uri(uri)
suffix = $3
end
uri = "#{uri}/" unless uri.end_with?("/")
uri = URI(uri)
require_relative "vendored_uri"
uri = Bundler::URI(uri)
unless uri.absolute?
raise ArgumentError, format("Gem sources must be absolute. You provided '%s'.", uri)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/bundler/source/git.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative "../vendored_fileutils"
require "uri"

module Bundler
class Source
Expand Down Expand Up @@ -285,7 +284,7 @@ def uri_hash
if uri =~ %r{^\w+://(\w+@)?}
# Downcase the domain component of the URI
# and strip off a trailing slash, if one is present
input = URI.parse(uri).normalize.to_s.sub(%r{/$}, "")
input = Bundler::URI.parse(uri).normalize.to_s.sub(%r{/$}, "")
else
# If there is no URI scheme, assume it is an ssh/git URI
input = uri
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/source/git/git_proxy.rb
Expand Up @@ -217,7 +217,7 @@ def uri_escaped_with_configured_credentials
# Adds credentials to the URI as Fetcher#configured_uri_for does
def configured_uri_for(uri)
if /https?:/ =~ uri
remote = URI(uri)
remote = Bundler::URI(uri)
config_auth = Bundler.settings[remote.to_s] || Bundler.settings[remote.host]
remote.userinfo ||= config_auth
remote.to_s
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/source/rubygems.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "uri"
require "rubygems/user_interaction"

module Bundler
Expand Down Expand Up @@ -328,9 +327,10 @@ def cached_path(spec)
def normalize_uri(uri)
uri = uri.to_s
uri = "#{uri}/" unless uri =~ %r{/$}
uri = URI(uri)
require_relative "../vendored_uri"
uri = Bundler::URI(uri)
raise ArgumentError, "The source must be an absolute URI. For example:\n" \
"source 'https://rubygems.org'" if !uri.absolute? || (uri.is_a?(URI::HTTP) && uri.host.nil?)
"source 'https://rubygems.org'" if !uri.absolute? || (uri.is_a?(Bundler::URI::HTTP) && uri.host.nil?)
uri
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/source/rubygems/remote.rb
Expand Up @@ -48,7 +48,7 @@ def apply_auth(uri, auth)
end

uri
rescue URI::InvalidComponentError
rescue Bundler::URI::InvalidComponentError
error_message = "Please CGI escape your usernames and passwords before " \
"setting them for authentication."
raise HTTPError.new(error_message)
Expand Down
10 changes: 7 additions & 3 deletions lib/bundler/uri_credentials_filter.rb
Expand Up @@ -7,7 +7,11 @@ module URICredentialsFilter
def credential_filtered_uri(uri_to_anonymize)
return uri_to_anonymize if uri_to_anonymize.nil?
uri = uri_to_anonymize.dup
uri = URI(uri.to_s) unless uri.is_a?(URI)
if uri.is_a?(String)
require_relative "vendored_uri"
uri = Bundler::URI(uri)
end

if uri.userinfo
# oauth authentication
if uri.password == "x-oauth-basic" || uri.password == "x"
Expand All @@ -17,9 +21,9 @@ def credential_filtered_uri(uri_to_anonymize)
end
uri.password = nil
end
return uri if uri_to_anonymize.is_a?(URI)
return uri.to_s if uri_to_anonymize.is_a?(String)
rescue URI::InvalidURIError # uri is not canonical uri scheme
uri
rescue Bundler::URI::InvalidURIError # uri is not canonical uri scheme
uri
end

Expand Down