simpleqt opened a new pull request, #644:
URL: https://github.com/apache/commons-csv/pull/644
With `QuoteMode.ALL`, a null value is printed as `quotedNullString`, which
`CSVFormat.Builder` builds by concatenating the quote character around the null
marker. A marker that itself contains the quote character closes its own
encapsulation, so the printer emits CSV its own parser rejects:
```java
CSVFormat format =
CSVFormat.DEFAULT.builder().setNullString("N\"A").setQuoteMode(QuoteMode.ALL).get();
// printer.printRecord("x", null) -> "x","N"A"
// CSVParser.parse(that output, format) -> Invalid character between
encapsulated token and delimiter
```
`CSV-328` fixed a quoted null marker built in the wrong setter order;
embedded quote characters in the marker were never escaped.
`setQuotedNullString()` now doubles the quote character inside the marker,
the same way the printer does for an ordinary value, so the emitted token stays
a single valid encapsulated field and round-trips through `CSVParser`.
## Test
`CSVPrinterTest.testQuotedNullStringEscapesEmbeddedQuoteCharacter` prints
`("x", null)` with a marker that contains the quote character, asserts the
exact CSV text, and then parses it back and asserts both values. With the
source change reverted:
```
CSVPrinterTest.testQuotedNullStringEscapesEmbeddedQuoteCharacter:2303
expected: <"x","N""A"> but was: <"x","N"A">
Tests run: 1, Failures: 1
```
With the change: the focused test passes, and the full module suite (`mvn -B
-o -ntp "-DargLine=-Dfile.encoding=UTF-8" test`, needed because this host's
default encoding is GBK) passes. The commit carries an `Assisted-By:` trailer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]