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

Commit

Permalink
Use vendorized version of uri library
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Dec 8, 2019
1 parent 8f80bda commit 97b7bbc
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 81 deletions.
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).
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
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
4 changes: 2 additions & 2 deletions lib/bundler/plugin/api/source.rb
Expand Up @@ -106,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 @@ -168,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
8 changes: 4 additions & 4 deletions lib/bundler/settings.rb
Expand Up @@ -151,8 +151,8 @@ def local_overrides

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

gem_mirrors.for(uri.to_s).uri
Expand Down Expand Up @@ -423,8 +423,8 @@ def self.normalize_uri(uri)
suffix = $3
end
uri = "#{uri}/" unless uri.end_with?("/")
require "uri"
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
2 changes: 1 addition & 1 deletion lib/bundler/source/git.rb
Expand Up @@ -284,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
Expand Up @@ -327,10 +327,10 @@ def cached_path(spec)
def normalize_uri(uri)
uri = uri.to_s
uri = "#{uri}/" unless uri =~ %r{/$}
require "uri"
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
6 changes: 3 additions & 3 deletions lib/bundler/uri_credentials_filter.rb
Expand Up @@ -8,8 +8,8 @@ def credential_filtered_uri(uri_to_anonymize)
return uri_to_anonymize if uri_to_anonymize.nil?
uri = uri_to_anonymize.dup
if uri.is_a?(String)
require "uri"
uri = URI(uri)
require_relative "vendored_uri"
uri = Bundler::URI(uri)
end

if uri.userinfo
Expand All @@ -23,7 +23,7 @@ def credential_filtered_uri(uri_to_anonymize)
end
return uri.to_s if uri_to_anonymize.is_a?(String)
uri
rescue URI::InvalidURIError # uri is not canonical uri scheme
rescue Bundler::URI::InvalidURIError # uri is not canonical uri scheme
uri
end

Expand Down
6 changes: 3 additions & 3 deletions spec/bundler/fetcher/base_spec.rb
Expand Up @@ -36,7 +36,7 @@ class TestClass < described_class; end
end

describe "#fetch_uri" do
let(:remote_uri_obj) { URI("http://rubygems.org") }
let(:remote_uri_obj) { Bundler::URI("http://rubygems.org") }

before { allow(subject).to receive(:remote_uri).and_return(remote_uri_obj) }

Expand All @@ -49,10 +49,10 @@ class TestClass < described_class; end
end

context "when the remote uri's host is not rubygems.org" do
let(:remote_uri_obj) { URI("http://otherhost.org") }
let(:remote_uri_obj) { Bundler::URI("http://otherhost.org") }

it "should return the remote uri" do
expect(subject.fetch_uri).to eq(URI("http://otherhost.org"))
expect(subject.fetch_uri).to eq(Bundler::URI("http://otherhost.org"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/fetcher/compact_index_spec.rb
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Bundler::Fetcher::CompactIndex do
let(:downloader) { double(:downloader) }
let(:display_uri) { URI("http://sampleuri.com") }
let(:display_uri) { Bundler::URI("http://sampleuri.com") }
let(:remote) { double(:remote, :cache_slug => "lsjdf", :uri => display_uri) }
let(:compact_index) { described_class.new(downloader, remote, display_uri) }

Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/fetcher/dependency_spec.rb
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Bundler::Fetcher::Dependency do
let(:downloader) { double(:downloader) }
let(:remote) { double(:remote, :uri => URI("http://localhost:5000")) }
let(:remote) { double(:remote, :uri => Bundler::URI("http://localhost:5000")) }
let(:display_uri) { "http://sample_uri.com" }

subject { described_class.new(downloader, remote, display_uri) }
Expand Down Expand Up @@ -258,7 +258,7 @@
end

describe "#dependency_api_uri" do
let(:uri) { URI("http://gem-api.com") }
let(:uri) { Bundler::URI("http://gem-api.com") }

context "with gem names" do
let(:gem_names) { %w[foo bar bundler rubocop] }
Expand Down
26 changes: 13 additions & 13 deletions spec/bundler/fetcher/downloader_spec.rb
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Bundler::Fetcher::Downloader do
let(:connection) { double(:connection) }
let(:redirect_limit) { 5 }
let(:uri) { URI("http://www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://www.uri-to-fetch.com/api/v2/endpoint") }
let(:options) { double(:options) }

subject { described_class.new(connection, redirect_limit) }
Expand Down Expand Up @@ -41,19 +41,19 @@
before { http_response["location"] = "http://www.redirect-uri.com/api/v2/endpoint" }

it "should try to fetch the redirect uri and iterate the # requests counter" do
expect(subject).to receive(:fetch).with(URI("http://www.uri-to-fetch.com/api/v2/endpoint"), options, 0).and_call_original
expect(subject).to receive(:fetch).with(URI("http://www.redirect-uri.com/api/v2/endpoint"), options, 1)
expect(subject).to receive(:fetch).with(Bundler::URI("http://www.uri-to-fetch.com/api/v2/endpoint"), options, 0).and_call_original
expect(subject).to receive(:fetch).with(Bundler::URI("http://www.redirect-uri.com/api/v2/endpoint"), options, 1)
subject.fetch(uri, options, counter)
end

context "when the redirect uri and original uri are the same" do
let(:uri) { URI("ssh://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("ssh://username:password@www.uri-to-fetch.com/api/v2/endpoint") }

before { http_response["location"] = "ssh://www.uri-to-fetch.com/api/v1/endpoint" }

it "should set the same user and password for the redirect uri" do
expect(subject).to receive(:fetch).with(URI("ssh://username:password@www.uri-to-fetch.com/api/v2/endpoint"), options, 0).and_call_original
expect(subject).to receive(:fetch).with(URI("ssh://username:password@www.uri-to-fetch.com/api/v1/endpoint"), options, 1)
expect(subject).to receive(:fetch).with(Bundler::URI("ssh://username:password@www.uri-to-fetch.com/api/v2/endpoint"), options, 0).and_call_original
expect(subject).to receive(:fetch).with(Bundler::URI("ssh://username:password@www.uri-to-fetch.com/api/v1/endpoint"), options, 1)
subject.fetch(uri, options, counter)
end
end
Expand Down Expand Up @@ -84,7 +84,7 @@
end

context "when the there are credentials provided in the request" do
let(:uri) { URI("http://user:password@www.uri-to-fetch.com") }
let(:uri) { Bundler::URI("http://user:password@www.uri-to-fetch.com") }

it "should raise a Bundler::Fetcher::BadAuthenticationError that doesn't contain the password" do
expect { subject.fetch(uri, options, counter) }.
Expand All @@ -102,7 +102,7 @@
end

context "when the there are credentials provided in the request" do
let(:uri) { URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }

it "should raise a Bundler::Fetcher::FallbackError that doesn't contain the password" do
expect { subject.fetch(uri, options, counter) }.
Expand Down Expand Up @@ -137,7 +137,7 @@
context "when there is a user provided in the request" do
context "and there is also a password provided" do
context "that contains cgi escaped characters" do
let(:uri) { URI("http://username:password%24@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username:password%24@www.uri-to-fetch.com/api/v2/endpoint") }

it "should request basic authentication with the username and password" do
expect(net_http_get).to receive(:basic_auth).with("username", "password$")
Expand All @@ -146,7 +146,7 @@
end

context "that is all unescaped characters" do
let(:uri) { URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
it "should request basic authentication with the username and proper cgi compliant password" do
expect(net_http_get).to receive(:basic_auth).with("username", "password")
subject.request(uri, options)
Expand All @@ -155,7 +155,7 @@
end

context "and there is no password provided" do
let(:uri) { URI("http://username@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username@www.uri-to-fetch.com/api/v2/endpoint") }

it "should request basic authentication with just the user" do
expect(net_http_get).to receive(:basic_auth).with("username", nil)
Expand All @@ -164,7 +164,7 @@
end

context "that contains cgi escaped characters" do
let(:uri) { URI("http://username%24@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username%24@www.uri-to-fetch.com/api/v2/endpoint") }

it "should request basic authentication with the proper cgi compliant password user" do
expect(net_http_get).to receive(:basic_auth).with("username$", nil)
Expand Down Expand Up @@ -244,7 +244,7 @@
end

context "when the there are credentials provided in the request" do
let(:uri) { URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
let(:uri) { Bundler::URI("http://username:password@www.uri-to-fetch.com/api/v2/endpoint") }
before do
allow(net_http_get).to receive(:basic_auth).with("username", "password")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/fetcher/index_spec.rb
Expand Up @@ -18,7 +18,7 @@

context "error handling" do
shared_examples_for "the error is properly handled" do
let(:remote_uri) { URI("http://remote-uri.org") }
let(:remote_uri) { Bundler::URI("http://remote-uri.org") }
before do
allow(subject).to receive(:remote_uri).and_return(remote_uri)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/fetcher_spec.rb
Expand Up @@ -3,7 +3,7 @@
require "bundler/fetcher"

RSpec.describe Bundler::Fetcher do
let(:uri) { URI("https://example.com") }
let(:uri) { Bundler::URI("https://example.com") }
let(:remote) { double("remote", :uri => uri, :original_uri => nil) }

subject(:fetcher) { Bundler::Fetcher.new(remote) }
Expand Down Expand Up @@ -45,7 +45,7 @@
end

context "when a rubygems source mirror is set" do
let(:orig_uri) { URI("http://zombo.com") }
let(:orig_uri) { Bundler::URI("http://zombo.com") }
let(:remote_with_mirror) do
double("remote", :uri => uri, :original_uri => orig_uri, :anonymized_uri => uri)
end
Expand Down

0 comments on commit 97b7bbc

Please sign in to comment.