diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index 802f6dfa7..047650a76 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -263,6 +263,7 @@ module Vagrant # # @return [Hash] def find_by_prefix(prefix) + return nil if prefix.nil? @machines.each do |uuid, data| return data.merge("id" => uuid) if uuid.start_with?(prefix) end diff --git a/test/unit/vagrant/machine_index_test.rb b/test/unit/vagrant/machine_index_test.rb index 682ac7583..5556063af 100644 --- a/test/unit/vagrant/machine_index_test.rb +++ b/test/unit/vagrant/machine_index_test.rb @@ -105,6 +105,7 @@ describe Vagrant::MachineIndex do it "returns nil if the machine doesn't exist" do expect(subject.get("foo")).to be_nil + expect(subject.get(nil)).to be_nil end it "returns a valid entry if the machine exists" do @@ -139,6 +140,11 @@ describe Vagrant::MachineIndex do expect(subject.include?("b")).to be(true) end + it "should return false if given nil input" do + expect(subject.include?(nil)).to be(false) + end + + it "locks the entry so subsequent gets fail" do result = subject.get("bar") expect(result).to_not be_nil