diff --git a/lib/vagrant/util/credential_scrubber.rb b/lib/vagrant/util/credential_scrubber.rb index 08fc7c563..6acb3f37a 100644 --- a/lib/vagrant/util/credential_scrubber.rb +++ b/lib/vagrant/util/credential_scrubber.rb @@ -30,7 +30,7 @@ module Vagrant # @param [String] string # @return [String] def self.desensitize(string) - string = string.dup + string = string.to_s.dup sensitive_strings.each do |remove| string.gsub!(remove, REPLACEMENT_TEXT) end @@ -39,7 +39,10 @@ module Vagrant # Register a sensitive string to be scrubbed def self.sensitive(string) - sensitive_strings.push(string).uniq! + string = string.to_s.dup + if string.length > 0 + sensitive_strings.push(string).uniq! + end nil end diff --git a/test/unit/vagrant/util/credential_scrubber_test.rb b/test/unit/vagrant/util/credential_scrubber_test.rb index c1815d964..e206fd763 100644 --- a/test/unit/vagrant/util/credential_scrubber_test.rb +++ b/test/unit/vagrant/util/credential_scrubber_test.rb @@ -34,6 +34,16 @@ describe Vagrant::Util::CredentialScrubber do subject.sensitive("value") expect(subject.sensitive_strings.count("value")).to eq(1) end + + it "should not add an empty string" do + subject.sensitive("") + expect(subject.sensitive_strings).to be_empty + end + + it "should type cast input to string" do + subject.sensitive(2) + expect(subject.sensitive_strings.first).to eq("2") + end end describe ".unsensitive" do