summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-10-17 15:36:29 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2013-10-17 16:37:56 -0700
commitf1f131741b55b5c4a3d4e1ddd9003ea0037458b9 (patch)
tree59921add92d11c711e1e382cc4c202ef63b4765f
parent11aed66b7d2b71425c75b4361fcbc684b0cdc390 (diff)
downloadohai-lcg/force-encode.tar.gz
force encode all strings to UTF-8lcg/force-encode
- this is a bit of a hack for ohai-6 while we're still using popen4 instead of mixlib-shellout - this may mean that we poorly support ISO-8851 / Shift_JIS or other non-UTF-8 encodings for characters where there is no translation between the external encoding and UTF-8 - this essentially standardizes on using UTF-8 internally
-rw-r--r--lib/ohai/mixin/command.rb7
-rw-r--r--spec/unit/mixin/command_spec.rb8
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb
index a719e274..76cebb63 100644
--- a/lib/ohai/mixin/command.rb
+++ b/lib/ohai/mixin/command.rb
@@ -128,12 +128,12 @@ module Ohai
#
# Thanks Ara!
def popen4(cmd, args={}, &b)
-
+
## Disable garbage collection to work around possible bug in MRI
# Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
# See OHAI-330 / CHEF-2916 / CHEF-1305
GC.disable
-
+
# Waitlast - this is magic.
#
# Do we wait for the child process to die before we yield
@@ -329,9 +329,10 @@ module Ohai
# have encoding methods.
if "".respond_to?(:force_encoding) && defined?(Encoding)
o.string.force_encoding(Encoding.default_external)
+ o.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
e.string.force_encoding(Encoding.default_external)
+ e.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
end
-
b[cid, pi[0], o, e]
results.last
end
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb
index 9fd30402..26189dfd 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/command_spec.rb
@@ -50,17 +50,17 @@ describe Ohai::Mixin::Command, "popen4" do
Encoding.default_internal = @saved_default_internal
end
- it "should force encode the string to US_ASCII" do
+ it "should force encode the string to UTF-8" do
extend Ohai::Mixin::Command
snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
- snowy.encoding.should == Encoding::US_ASCII
+ snowy.encoding.should == Encoding::UTF_8
end
end
- it "[OHAI-275] should mark strings as in the default external encoding" do
+ it "should force encode the string to UTF-8" do
extend Ohai::Mixin::Command
snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
- snowy.encoding.should == Encoding.default_external
+ snowy.encoding.should == Encoding::UTF_8
end
end