ckruse / CFPropertyList

Read, write and manipulate both binary and XML property lists as defined by apple
MIT License
212 stars 47 forks source link

CFPropertyList.native_types doesn't preserve Blob/raw data #27

Closed glarizza closed 10 years ago

glarizza commented 10 years ago

Discovered this today as I was trying to do some more work with CFPropertyList. See this example code that I ran in Pry (using CFPropertyList 2.2.5) that must be run as the root user (in order to read the user's plist)

require 'CFPropertyList'

# Load any OS X 10.8 or higher User's Plist
plist_obj = CFPropertyList::List.new(:file => "/var/db/dslocal/nodes/Default/users/puppetuser.plist")

# This returns CFPropertyList::CFData
plist_obj.value.value['ShadowHashData'].value[0].class

# All the types
plist_obj.value.value.each {|k,v| puts v.value.first.class };0

# Convert to native types
hash = CFPropertyList.native_types(plist_obj.value)

# This returns a string, not CFPropertyList::CFData or CFPropertyList::Blob
hash['ShadowHashData'][0].class

# All the types - all Strings
hash.each {|k,v| puts v.first.class }

# Now let's try saving this to another plist:
new_plist = CFPropertyList::List.new
new_plist.value = CFPropertyList.guess(hash)

# This should error with Encoding::InvalidByteSequenceError
new_plist.save('/tmp/new.plist', CFPropertyList::List::FORMAT_BINARY)

EDIT: I'm a moron and can't tell the difference between CFDate and CFData. I do think I found the problem, though, and will submit a pull request momentarily...

glarizza commented 10 years ago

28 resolves this issue for me. Please take a peek and let me know if it looks good to you :) I JUST realized that I should probably also have tests for this...so let me look at doing that too.

ckruse commented 10 years ago

It would be GREAT to have a test for that. Can you provide one? If not I will write one myself, but it would be nice to have your name in the git repo beside the test file since you fixed the bug.

glarizza commented 10 years ago

I can certainly take a stab at it today - let me ping you when I'm done :)

On Sunday, December 22, 2013, Christian Kruse wrote:

It would be GREAT to have a test for that. Can you provide one? If not I will write one myself, but it would be nice to have your name in the git repo beside the test file since you fixed the bug.

— Reply to this email directly or view it on GitHubhttps://github.com/ckruse/CFPropertyList/issues/27#issuecomment-31106845 .

Gary Larizza Professional Services Engineer Puppet Labs

ckruse commented 10 years ago

Ok, wrote a test and pushed a new version.