CSV export quoting issues

MrC
MrC
Volunteer Moderator
edited April 2023 in 1Password 3 – 7 for Mac

The CSV export is not correctly CSV-quoting Tags data. It is using backslash to escape a double-quote, but it should be doubling up the double-quote. Example:

"{(
    \"1PIF Import 12-5-18\",
    Favorite
)}"

should be:

"{(
    ""1PIF Import 12-5-18"",
    Favorite
)}"

1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • MrC
    MrC
    Volunteer Moderator
    edited May 2019

    Ooof - this appears to be everywhere.

    Let's take an example field, say password, with a value of:

    012"345\"678
    

    This gets stored in the CSV as:

    "012\"345\\"678"
    

    But this is horribly broken.

    First, fields in the CSV are not correctly quote-escaped.

    Second, if backslash is your escape character, then the first backslash in the double backslash sequence escapes the second backslash, but that leaves another unquoted double-quote in the CSV.

    But it gets worse:

    012"345\"678\\"
    

    gets stored as:

    "012\"345\\"678\\\""
    

    In the trailing sequence of three backslashes and a double-quote, the first backslash escapes the next one, leaving a single backslash, and the third one escapes the double quote. This would leave \" as the replacement, and this is wrong.

    Maybe then only the backslash + double quote sequence should be replaced with a double-quote, and backslash is not a general quote character. So let's try:

    012"345\"67,8\\"\
    

    which leads to the data in the CSV:

    "012\"345\\"67,8\\\"\"
    

    Using the rules that would interpolate as:

    012"345\"67,8\""

    so we lost a trailing backslash in the data. It is impossible to detect, while reading the character stream, when to replace \" with " and when not to.

    So the backslash is an escape character, except when it isn't. The CSV is lossy, because there are no consistent quoting rules. The quoting algorithm used worked on export, but won't work on import (the conversion is one-way).

    Looks like someone didn't convert JSON quoted data into correctly quoted CSV data, nor think/learn about the CSV quoting rules, so the CSV export is not valid CSV. But worse, the original data cannot be restored from the CSV due to the ambiguities and incorrect application of your quoting rules.

    Note: The sample CSV I generated cannot be interpreted correctly by Numbers or LibreOffice's Calc, due to these issues here and in the first post.

  • Hi @MrC ,

    Thanks for taking the time to send in all of the information. I've raised an issue to have it looked at and fixed. I do have a question. It's likely a bug in the JSON conversion.

    Cheers,
    Kevin

    ref: apple-3681

This discussion has been closed.