Skip to content

Quote escape configured to double quote (quote value) character if escape not detected #414

@ghost

Description

environment:
univocity-parsers 2.8.3
AdoptOpenJDK 11.0.8+10

Hi,

I have a simple configuration that reads a few lines from a csv file. The content in the file does not have enough information to detect and set the quote character and the quote escape character. However, after parsing, the detected csv format for quote escape is incorrect after I have explicitly set the value and the data has not driven any change through detection.
When quote escape is defaulted to backslash, the result csv format is always double quote.

CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setQuoteEscape('\\');

CsvParser parser = new CsvParser(settings);
parseAll(...)
...
CsvFormat csvFormat = parser.getDetectedFormat();

I poked around a bit and I think there is an issue in the CsvFormatDetector at line 246,
where
char quoteEscape = max(escape, totals, quote);
should be
char quoteEscape = max(escape, totals, quoteEscape);

If I understand the logic correctly, it is wanting to use the escape most used or default to a value if no detection. The value should be the quote escape, and not the quote.

Thanks,
James

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions