You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(FACT-3497) Facter should not fail when binary data is detected
This commit updates LegacyFacter::Util::Normalization.normalize_string to
accept fact values with ASCII 8-BIT without immediately failing. When a fact
value with ASCII 8-BIT is detected but can be force encoded to UTF-8, Facter
will log a debug message with the fact name and value. Facter will only error
(with the fact name & value) when the fact value cannot be successfully force
encoded to UTF-8.
This commit also updates all the normalize methods in
LegacyFacter::Util::Normalization to take in 2 parameters now: the fact name &
value so the debug and error messages can include the fact name. This helps
users more easily figure out which fact is causing issues and has binary.
raiseNormalizationError,"custom fact \"#{fact_name}\" with value: #{value_copy_encoding} contains binary data and could not be force encoded to UTF-8"unlessvalue_copy_encoding.valid_encoding?
54
+
55
+
log.debug("custom fact \"#{fact_name}\" with value: #{value} contained binary data and was force encoded to UTF-8 and now has the value: #{value_copy_encoding}")
56
+
value=value_copy_encoding
54
57
55
-
value=value.encode(Encoding::UTF_8)
58
+
else
59
+
value=value.encode(Encoding::UTF_8)
60
+
end
56
61
57
62
unlessvalue.valid_encoding?
58
63
raiseNormalizationError,"String #{value.inspect} doesn't match the reported encoding #{value.encoding}"
@@ -73,9 +78,9 @@ def normalize_string(value)
73
78
# @raise [NormalizationError] If one of the elements failed validation
74
79
# @param value [Array]
75
80
# @return [void]
76
-
defnormalize_array(value)
81
+
defnormalize_array(fact_name,value)
77
82
value.collectdo |elem|
78
-
normalize(elem)
83
+
normalize(fact_name,elem)
79
84
end
80
85
end
81
86
@@ -85,8 +90,12 @@ def normalize_array(value)
85
90
# @raise [NormalizationError] If one of the keys or values failed normalization
it'accepts ASCII 8-BIT (binary) string that can be successfully force encoded to UTF-8 and logs a debug message with the fact name and value and returns UTF-8 encoded version of the passed in string'do
expect(logger).toreceive(:debug).with(/custom fact "" with value: #{str} contained binary data and was force encoded to UTF-8 and now has the value: #{str}/)
35
+
value=normalization.normalize('',str)
36
+
expect(value).toeq('test')
37
+
expect(value.encoding).toeq(Encoding::UTF_8)
38
+
end
39
+
40
+
it'errors when given binary string that cannot be successfully force encoded to UTF-8'do
0 commit comments