Skip to content

fix(csv): escape quote characters in the quoted null marker - #644

Open
simpleqt wants to merge 1 commit into
apache:masterfrom
simpleqt:fix/null-marker-quoted-marker
Open

simpleqt wants to merge 1 commit into
apache:masterfrom
simpleqt:fix/null-marker-quoted-marker

Conversation

@simpleqt

Copy link
Copy Markdown

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:

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.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

CSVFormat.Builder builds quotedNullString, the token QuoteMode.ALL uses for null values, by
concatenating the quote character around the null marker. A marker that contains the quote
character closes its own encapsulation, so CSVPrinter emits CSV that its parser rejects with
"Invalid character between encapsulated token and delimiter". CSV-328 already fixed an invalid
quoted null marker built in the wrong setter order; this escapes embedded quote characters too,
the same way printWithQuotes does for a value.

Assisted-By: DeepSeek Harness
@simpleqt
simpleqt force-pushed the fix/null-marker-quoted-marker branch from 5b5029d to 6e55808 Compare November 16, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants