ckruse / CFPropertyList

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

long strings are reflowed when using :formatted and the REXML parser #44

Closed ccaviness closed 8 years ago

ccaviness commented 8 years ago

The rexml pretty formatter will break up and indent long strings, changing the actual content of the string.

This means when reading the generated plist, you don't get the same data out.

With a 30-character string:

$ ruby -rcfpropertylist -e 'p = CFPropertyList::List.new; p.value = CFPropertyList.guess("foo" * 10); puts p.to_str(CFPropertyList::List::FORMAT_XML, :formatted => true)'
<?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">
<plist version="1.0">
  <string>foofoofoofoofoofoofoofoofoofoo</string>
</plist>

With a 90-character string:

$ ruby -rcfpropertylist -e 'p = CFPropertyList::List.new; p.value = CFPropertyList.guess("foo" * 30); puts p.to_str(CFPropertyList::List::FORMAT_XML, :formatted => true)'
<?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">
<plist version="1.0">
  <string>
    foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
  </string>
</plist>

In the 90-character example, the string value has been changed, and now starts with a newline and two spaces.

The rexml pretty formatter has a width attribute: http://ruby-doc.org/stdlib-2.1.0/libdoc/rexml/rdoc/REXML/Formatters/Pretty.html

Adding: f.width = 9999 following https://github.com/ckruse/CFPropertyList/blob/master/lib/cfpropertylist/rbREXMLParser.rb#L42 works around this problem.

nokogiri's formatter doesn't do this. I did not test libxml.

ccaviness commented 8 years ago

https://github.com/ckruse/CFPropertyList/pull/45

ckruse commented 8 years ago

Hm, good point, although I don't think that width = 9999 is a valid solution… instead we should use Float::INFINITY

ckruse commented 8 years ago

Thanks for reporting!

ckruse commented 8 years ago

… and a bugfix release is out

ccaviness commented 8 years ago

Much nicer solution, and with tests! Thanks.