diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-06-28 16:20:37 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-06-28 16:20:37 -0700 |
commit | bcd053fedc1d1a68bdfbbbac37879b19a89f533c (patch) | |
tree | f926ed3f93e29491cfc873fe4c91c810541f8b27 /lib/chef/util | |
parent | 59e7020286dfa02201409f05be6efb42639bff85 (diff) | |
download | chef-bcd053fedc1d1a68bdfbbbac37879b19a89f533c.tar.gz |
fix 1.9 mixlib-shellout encoding issues
Diffstat (limited to 'lib/chef/util')
-rw-r--r-- | lib/chef/util/diff.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index 9157daf85e..4d46108cdd 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -104,9 +104,14 @@ class Chef return "(long diff of over #{diff_output_threshold} characters, diff output suppressed)" else diff_str = result.stdout - if diff_str.respond_to?(:encoding) - # in ruby 1.9 diff_str will be ASCII-8BIT, in 2.0 it will be default_external (e.g. UTF-8) - # we will post this as JSON which needs UTF-8, so we force to UTF-8 here as part of the API + if Object.const_defined? :Encoding # ruby >= 1.9 + if ( diff_str.encoding == Encoding::ASCII_8BIT && + diff_str.encoding != Encoding.default_external && + RUBY_VERSION.to_f < 2.0 ) + # @todo mixlib-shellout under ruby 1.9 hands back an ASCII-8BIT encoded string, which needs to + # be fixed to the default external encoding -- this should be moved into mixlib-shellout + diff_str = diff_str.force_encoding(Encoding.default_external) + end diff_str.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?') end @diff = diff_str.split("\n") |