diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-04 12:04:55 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-04 12:04:55 -0700 |
commit | c6c7329ff54851390e0e84d0b681ee8396b3f34c (patch) | |
tree | bfcc03815549fc1d95b72031b117d0a7c791db05 /lib | |
parent | c8af4993151e6636008b1ae7cdae01008247ccc9 (diff) | |
parent | bf97afa34c5da66c84e8f07f83e249d1c25811e2 (diff) | |
download | chef-c6c7329ff54851390e0e84d0b681ee8396b3f34c.tar.gz |
Merge pull request #3320 from chef/lcg/node-utf8-sanitize
Lcg/node utf8 sanitize
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/http/json_input.rb | 7 | ||||
-rw-r--r-- | lib/chef/node.rb | 10 |
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/chef/http/json_input.rb b/lib/chef/http/json_input.rb index 23ccc3a8a7..3296d8821f 100644 --- a/lib/chef/http/json_input.rb +++ b/lib/chef/http/json_input.rb @@ -25,14 +25,19 @@ class Chef # Middleware that takes json input and turns it into raw text class JSONInput + attr_accessor :opts + def initialize(opts={}) + @opts = opts end def handle_request(method, url, headers={}, data=false) if data && should_encode_as_json?(headers) headers.delete_if { |key, _value| key.downcase == 'content-type' } headers["Content-Type"] = 'application/json' - data = Chef::JSONCompat.to_json(data) + json_opts = {} + json_opts[:validate_utf8] = opts[:validate_utf8] if opts.has_key?(:validate_utf8) + data = Chef::JSONCompat.to_json(data, json_opts) # Force encoding to binary to fix SSL related EOFErrors # cf. http://tickets.opscode.com/browse/CHEF-2363 # http://redmine.ruby-lang.org/issues/5233 diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 9823185ede..8c41d7e10e 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -83,7 +83,15 @@ class Chef end def chef_server_rest - @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) + # for saving node data we use validate_utf8: false which will not + # raise an exception on bad utf8 data, but will replace the bad + # characters and render valid JSON. + @chef_server_rest ||= Chef::REST.new( + Chef::Config[:chef_server_url], + Chef::Config[:node_name], + Chef::Config[:client_key], + validate_utf8: false, + ) end # Set the name of this Node, or return the current name. |