Prevent URI parse errors when checking box name

Fixes #8758
This commit is contained in:
Chris Roberts 2017-07-07 11:43:16 -07:00
parent 4f7938726e
commit da1b5765c7
2 changed files with 28 additions and 2 deletions

View File

@ -31,9 +31,13 @@ module Vagrant
@download_interrupted = false
unless env[:box_name].nil?
begin
if URI.parse(env[:box_name]).kind_of?(URI::HTTP)
env[:ui].warn(I18n.t("vagrant.box_add_url_warn"))
end
rescue URI::InvalidURIError
# do nothing
end
end
url = Array(env[:box_url]).map do |u|

View File

@ -305,6 +305,28 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
end
end
context "with a box name containing invalid URI characters" do
it "should not raise an error" do
box_path = iso_env.box2_file(:virtualbox)
with_web_server(box_path) do |port|
box_url_name = "box name with spaces"
env[:box_name] = box_url_name
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(name).to eq(box_url_name)
expect(version).to eq("0")
expect(opts[:metadata_url]).to be_nil
true
}.and_return(box)
expect(app).to receive(:call).with(env)
subject.call(env)
end
end
end
context "with URL containing credentials" do
let(:username){ "box-username" }
let(:password){ "box-password" }