Skip to content

Commit b8d2e45

Browse files
(maint) Check for valid encoding from spawned process
When facter spawns a new process, it is possible that the encoding for the output will come back as a non-UTF8 string; for instance, when the locale is set to CP932 for Japanese. This can occur when the shell injects a string into the output, such as for a command- not-found type of error. In these cases, we should fall back to the external default encoding, otherwise ruby will error on string manipulations of strings that re not UTF-8.
1 parent 5735566 commit b8d2e45

File tree

1 file changed

+1
-0
lines changed
  • lib/facter/custom_facts/core/execution

1 file changed

+1
-0
lines changed

lib/facter/custom_facts/core/execution/base.rb

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def execute_command(command, on_fail = nil, logger = nil, timeout = nil)
106106
raise Facter::Core::Execution::ExecutionFailure.new, message
107107
end
108108

109+
out.force_encoding(Encoding.default_external) unless out.valid_encoding?
109110
[out.strip, stderr]
110111
end
111112

0 commit comments

Comments
 (0)