From d58690df32f0494a66508a144767a28aee5dbe9b Mon Sep 17 00:00:00 2001 From: JKimalane Date: Thu, 2 Dec 2021 14:36:48 +0200 Subject: [PATCH] attempt to fix once and for all the issue with json validation introduced with version 4.0.13 --- lib/chef/knife/mixin/helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chef/knife/mixin/helper.rb b/lib/chef/knife/mixin/helper.rb index 2654d32..60d521c 100644 --- a/lib/chef/knife/mixin/helper.rb +++ b/lib/chef/knife/mixin/helper.rb @@ -56,7 +56,7 @@ def validate_json(json) if evaled_json.is_a?(Hash) evaled_json.each do |key, value| - next unless printable?(value.to_s) + next if 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) @@ -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) + # returns true if string is free of non-printable characters (escape sequences) or includes '\n' or '\r', which is perfectly valid # this returns false for whitespace escape sequences as well, e.g. \n\t def printable?(string) - /[^[:print:]]|[[:space:]]/.match(string) + /[[:print:]]|[\n\r]/.match?(string) end end end