[Pkg-puppet-devel] [facter] 143/352: (#22107) Force ASCII-8BIT encoding on raw data in property lists
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:40 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit ecbe3cab0ceb7229880ed45ed9a97da47f9aa93b
Author: Dustin J. Mitchell <dustin at mozilla.com>
Date: Fri Aug 9 14:29:45 2013 -0400
(#22107) Force ASCII-8BIT encoding on raw data in property lists
Ruby-1.9 and up default to UTF-8 encoding for strings, but CFData is
used to store bytestrings in plists as read from file-like objects. So,
disregard the encoding returned from `obj.read`, treating the string as
a bytestring.
---
lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb b/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb
index cd7fcf1..3acdbba 100644
--- a/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb
+++ b/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb
@@ -164,7 +164,12 @@ module Facter::Util::CFPropertyList
when Object.const_defined?('BigDecimal') && object.is_a?(BigDecimal)
CFReal.new(object)
when object.respond_to?(:read)
- CFData.new(object.read(), CFData::DATA_RAW)
+ raw_data = object.read
+ # treat the data as a bytestring (ASCII-8BIT) if Ruby supports it. Do this by forcing
+ # the encoding, on the assumption that the bytes were read correctly, and just tagged with
+ # an inappropriate encoding, rather than transcoding.
+ raw_data.force_encoding(Encoding::ASCII_8BIT) if raw_data.respond_to?(:force_encoding)
+ CFData.new(raw_data, CFData::DATA_RAW)
when options[:converter_method] && object.respond_to?(options[:converter_method])
if options[:converter_with_opts]
Facter::Util::CFPropertyList.guess(object.send(options[:converter_method],options),options)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list