diff --git a/plugins/commands/login/middleware/add_authentication.rb b/plugins/commands/login/middleware/add_authentication.rb index a30f026e6..79083424d 100644 --- a/plugins/commands/login/middleware/add_authentication.rb +++ b/plugins/commands/login/middleware/add_authentication.rb @@ -35,11 +35,15 @@ module VagrantPlugins token = client.token env[:box_urls].map! do |url| - u = URI.parse(url) - if u.host != TARGET_HOST && REPLACEMENT_HOSTS.include?(u.host) - u.host = TARGET_HOST - u.to_s - else + begin + u = URI.parse(url) + if u.host != TARGET_HOST && REPLACEMENT_HOSTS.include?(u.host) + u.host = TARGET_HOST + u.to_s + else + url + end + rescue URI::Error url end end diff --git a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb index 8b7f40048..9a46506e7 100644 --- a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb +++ b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb @@ -125,6 +125,15 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do end end + it "ignores urls that it cannot parse" do + bad_url = "this is not a valid url" + # Ensure the bad URL does cause an exception + expect{ URI.parse(bad_url) }.to raise_error URI::Error + env[:box_urls] = [bad_url] + subject.call(env) + expect(env[:box_urls].first).to eq(bad_url) + end + it "returns original urls when not modified" do to_persist = "file:////path/to/box.box" to_change = VagrantPlugins::LoginCommand::AddAuthentication::