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

Revert #347 #375

Closed
wants to merge 1 commit into from
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
3 changes: 0 additions & 3 deletions lib/chef-vault/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,5 @@ class IdMismatch < Exceptions

class V1Format < Exceptions
end

class InvalidValue < Exceptions
end
end
end
28 changes: 0 additions & 28 deletions lib/chef/knife/mixin/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,10 @@ def values_from_file(file)
end

def values_from_json(json)
validate_json(json)
JSON.parse(json)
rescue JSON::ParserError
raise JSON::ParserError, "#{json} is not valid JSON!"
end

# I/P: json string
# Raises `InvalidValue` if any of the json's values contain non-printable characters.
def validate_json(json)
begin
evaled_json = eval(json) # rubocop: disable Security/Eval
rescue SyntaxError
raise ChefVault::Exceptions::InvalidValue, "#{json} is not valid JSON!"
end

if evaled_json.is_a?(Hash)
evaled_json.each do |key, value|
next unless printable?(value.to_s)

msg = "Value '#{value}' of key '#{key}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
ChefVault::Log.warn(msg)
end
end
end

# 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
def printable?(string)
/[^[:print:]]|[[:space:]]/.match(string)
end
end
end
end
27 changes: 0 additions & 27 deletions spec/chef/helper_spec.rb

This file was deleted.