Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Whitespace Characters as Vault Content #372

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/chef/knife/mixin/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def validate_json(json)

# I/P: String
# O/P: true/false
# returns true if string is free of non-printable characters (escape sequences)
# this returns false for whitespace escape sequences as well, e.g. \n\t
# returns true if string is free of non-printable and whitespace characters
# (escape sequences)
def printable?(string)
/[^[:print:]]/.match(string)
/[^[:graph:][:space:]]/.match(string)
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/chef/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
include ChefVault::Mixin::Helper

let(:json_data) { '{"username": "root", "password": "abcabc"}' }
let(:json_data_whitespace) { '{"username": "root", "password": "abc\nabc\tabc"}' }
let(:json_data_control_char) { '{"username": "root", "password": "abc\abc"}' }
let(:buggy_json_data) { '{"username": "root", "password": "abc\abc"' }

Expand All @@ -20,5 +21,9 @@
it "Not to raise error if valid data provided" do
expect { validate_json(json_data) }.to_not raise_error
end

it "Not to raise error if valid data with whitespace provided" do
expect { validate_json(json_data_whitespace) }.to_not raise_error
end
end
end
end