ckruse / CFPropertyList

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

Binary encoded plist returns <data></data> as strings instead of CFPropertyList::Blob #25

Closed kunalrm closed 10 years ago

kunalrm commented 10 years ago

When you execute CFPropertyList.native_types(plist.value) on a plist which has a in it and is binary encoded, the gem returns the contents as string instead of type CFPropertyList::Blob. The issue seems to be in the initialize methods for CFData. Attached is the patch which I think should fix the problem.

Patch: def initialize(value=nil,format=DATA_BASE64) if(format == DATA_RAW) @raw_value = Blob.new(value) else @value = value end end

Sample Plist: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

favoriteitems Controller CustomListItems CustomListItems Alias AAAAAACQAAMAAQAAzeaRzAAASCsAAAAAAAU4rgAGHwgA AMs02NwAAAAACSD//gAAAAAAAAAA/////wABAAgABTiu AAIQvgAOABAABwBEAHIAbwBwAGIAbwB4AA8ACAADAEMA YQBiABIAFVVzZXJzL2ttdWRnYWwvRHJvcGJveAAAEwAB LwAAFQACAA7//wAA Name Dropbox
kunalrm commented 10 years ago

Stupid github stripped all the tags in the plist but I think you get an idea of what the problem is. If you still need a sample binary encoded plist I can upload one.

ckruse commented 10 years ago

I'm very sorry, I've been really busy the last few days. I will have a look at this this evening, I've got about 5 hours traveling time to fill.

ckruse commented 10 years ago

Can you retry this with the latest version of this gem? I can't reproduce this:

pl = CFPropertyList::List.new(file: './test.plist') # test.plist is your example code
puts CFPropertyList.native_types(pl.value)['favoriteitems']['CustomListItems'][0]['Alias'].class.inspect
=> CFPropertyList::Blob

Best regards, Christian Kruse

ckruse commented 10 years ago

Closing because it works for me and OP doesn't respond