long strings are reflowed when using :formatted and the REXML parser
Closed this issue · 5 comments
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
.
Hm, good point, although I don't think that width = 9999
is a valid solution… instead we should use Float::INFINITY
Thanks for reporting!
… and a bugfix release is out
Much nicer solution, and with tests! Thanks.