jackson-dataformats-text icon indicating copy to clipboard operation
jackson-dataformats-text copied to clipboard

CSV STRICT_CHECK_FOR_QUOTING does not enclose value with newline character in double quotes

Open zhuhw opened this issue 1 year ago • 4 comments

If I enable STRICT_CHECK_FOR_QUOTING

public static void main(String[] args) throws JsonProcessingException {
    CsvFactory csvFactory = new CsvFactory();
    csvFactory.enable(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING);

    ObjectMapper objectMapper = Jackson.newObjectMapper(csvFactory);
    ObjectWriter writer = objectMapper.writer();
    String s = writer.writeValueAsString("line1\nline2");
    System.out.println(s);
}

The output is:

line1
line2

But when I disable the Feature, output becomes

"line1
line2"

If I change the newline character to a comma, the value is enclosed no matter I enable or disable this Feature:

"line1,line2"

This does not follow the https://www.ietf.org/rfc/rfc4180.txt item 2.6

zhuhw avatar Jun 06 '24 18:06 zhuhw

That does seem wrong to me, thank you for reporting.

Quick question: which version did you test with?

cowtowncoder avatar Jun 06 '24 19:06 cowtowncoder

We are on jackson-dataformat-csv-2.9.10.jar

zhuhw avatar Jun 07 '24 16:06 zhuhw

@zhuhw That is a rather old version (almost 5 years ago) and a lot has changed since then. Does the problem still occur with, say, 2.17.1?

I can try it now, but for future reference it is very strongly recommended to test with the latest release version to avoid wasting everyone's time on bugs that have already been fixed (or behavior changed).

cowtowncoder avatar Jun 07 '24 22:06 cowtowncoder

For example, #220 was fixed for 2.11.3 and seems like that might be fix for your issue @zhuhw ?

cowtowncoder avatar Jun 07 '24 23:06 cowtowncoder

Assuming this was fixed since I have seen no updates; closing.

May be re-opened with reproduction against recent version, if this still occurs.

cowtowncoder avatar Jul 10 '24 04:07 cowtowncoder