ebarnard / rust-plist

A rusty plist parser.
MIT License
71 stars 42 forks source link

InvalidData reading binary plist #22

Closed jchien14 closed 7 years ago

jchien14 commented 7 years ago

Haven't looked in detail, but this failed on both 0.2.1 and 0.1.3, giving Err(InvalidData).

$ defaults write /tmp/test.plist Test 1
$ defaults read /tmp/test.plist
{
    Test = 1;
}
>>> open('/tmp/test.plist', 'rb').read()
'bplist00\xd1\x01\x02TTestQ1\x08\x0b\x10\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12'

It worked when I converted it to XML, so I'm guessing it's an issue with the binary parser.

ebarnard commented 7 years ago

Thanks. Fixed in 0.2.2.

jchien14 commented 7 years ago

Thanks for the quick fix!

I notice when using 0.2.2, that the above plist isn't handled as I would expect it to. After I call plist.as_dictionary().get('Test'), the resulting Plist returns None when I call as_integer (also as_boolean) but returns the string "1" when I call as_string. Should as_integer never be called for binary plists?

It appears converting it to XML does also convert it as a string, so I guess this is correct -- just a bit unintuitive given the API options.

ebarnard commented 7 years ago

Looking at the defaults man page (https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/defaults.1.html) it seems like it defaults to writing a string unless you specify otherwise.

On 5 May 2017, at 20:06, jchien14 notifications@github.com wrote:

Thanks for the quick fix!

I notice when using 0.2.2, that the above plist isn't handled as I would expect it to. After I call plist.as_dictionary().get('Test'), the resulting Plist returns None when I call as_integer (also as_boolean) but returns the string "1" when I call as_string. Should as_integer never be called for binary plists?

It appears converting it to XML does also convert it as a string, so I guess this is correct -- just a bit unintuitive given the API options.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

ebarnard commented 7 years ago

as_X could be named better though.