netbe / Babelish

Chaotically confused, like Babel
http://netbe.github.io/Babelish
MIT License
254 stars 84 forks source link

csv2android doesn't escape HTML correctly #52

Closed benebun closed 9 years ago

benebun commented 9 years ago

Unfortunately, it seems that csv2android:

  1. doesn't escape HTML in the resulting XML and
  2. escapes quotes with backslashes

which makes it impossible to convert XML to CSV and back again to XML (presumably a common translation workflow).

Original XML with correctly escaped HTML:

  <string name="title">Title of &lt;a href="asd">File&lt;/a></string>

through android2csv results in:

title,"Title of <a href=""asd"">File</a>"

Converting it back to XML results in:

    <string name="title">Title of <a href=\"asd\">File</a></string>

Note the non-escaped < and the backslash escaped href attribute.

Converting it once again to CSV with android2csv then results in the following error:

    [...]/ruby-2.1.2/lib/ruby/2.1.0/rexml/parsers/baseparser.rb:373:in `pull_event':
    missing attribute quote (REXML::ParseException)
    Line: 4
    Position: 128
    Last 80 unconsumed characters:
    <a href=\"asd\">File</a></string> </resources>

With the manually fixed quotes the HTML tag gets truncated in the resulting CSV:

    title,Title of