File tree Expand file tree Collapse file tree
main/java/org/apache/commons/csv
test/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -806,6 +806,8 @@ public Builder setQuote(final Character quoteCharacter) {
806806 throw new IllegalArgumentException ("The quoteCharacter cannot be a line break" );
807807 }
808808 this .quoteCharacter = quoteCharacter ;
809+ final Character quote = quoteCharacter != null ? quoteCharacter : Constants .DOUBLE_QUOTE_CHAR ;
810+ this .quotedNullString = quote + nullString + quote ;
809811 return this ;
810812 }
811813
Original file line number Diff line number Diff line change @@ -1001,6 +1001,30 @@ void testQuoteCharSameAsDelimiterThrowsException_Deprecated() {
10011001 assertThrows (IllegalArgumentException .class , () -> CSVFormat .DEFAULT .withQuote ('!' ).withDelimiter ('!' ));
10021002 }
10031003
1004+ @ Test
1005+ void testQuotedNullStringTracksQuoteCharacter () throws IOException {
1006+ final StringBuilder out = new StringBuilder ();
1007+ // @formatter:off
1008+ final Builder builder = CSVFormat .DEFAULT .builder ();
1009+ final CSVFormat format = builder
1010+ .setQuoteMode (QuoteMode .ALL )
1011+ .setNullString ("NULL" )
1012+ .get ();
1013+ // @formatter:on
1014+ format .print (null , out , true );
1015+ assertEquals ("\" NULL\" " , out .toString ());
1016+ // set
1017+ out .setLength (0 );
1018+ builder .setQuote ('\'' );
1019+ builder .get ().print (null , out , true );
1020+ assertEquals ("'NULL'" , out .toString ());
1021+ // reset
1022+ out .setLength (0 );
1023+ builder .setQuote ((Character ) null );
1024+ builder .get ().print (null , out , true );
1025+ assertEquals ("\" NULL\" " , out .toString ());
1026+ }
1027+
10041028 @ Test
10051029 void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage () {
10061030 final Exception exception = assertThrows (IllegalArgumentException .class , () ->
You can’t perform that action at this time.
0 commit comments