Ignore empty strings registered as sensitive

Fixes #9462
This commit is contained in:
Chris Roberts 2018-02-15 17:02:34 -08:00
parent 610182593a
commit 330ee2e1eb
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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