CSV export quoting issues

MrCMrC Community Moderator
edited May 2019 in Mac Beta

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\",

should be:

    ""1PIF Import 12-5-18"",

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


  • MrCMrC Community Moderator
    edited May 2019

    Ooof - this appears to be everywhere.

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


    This gets stored in the CSV as:


    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:


    gets stored as:


    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:


    which leads to the data in the CSV:


    Using the rules that would interpolate as:


    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.

  • ag_kevinag_kevin Junior Member

    Team Member

    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.


    ref: apple-3681

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file