@@ -1963,6 +1963,30 @@ void testQuoteValueEndingWithSupplementaryDelimiterPrefix() throws IOException {
19631963 }
19641964 }
19651965
1966+ @ Test
1967+ void testQuoteValueWithLeadingOrTrailingUnicodeWhitespace () throws IOException {
1968+ // U+3000 IDEOGRAPHIC SPACE is Character.isWhitespace but greater than ' ', so ignoreSurroundingSpaces
1969+ // strips it on read. It must be quoted or the surrounding whitespace is lost on a round trip.
1970+ final String idSpace = " " ;
1971+ final CSVFormat format = CSVFormat .DEFAULT .builder ().setIgnoreSurroundingSpaces (true ).get ();
1972+ final StringWriter sw = new StringWriter ();
1973+ try (CSVPrinter printer = new CSVPrinter (sw , format )) {
1974+ printer .printRecord (idSpace + "a" + idSpace , "b" );
1975+ // A value without surrounding whitespace stays unquoted.
1976+ printer .printRecord ("ab" , "c" );
1977+ }
1978+ final String string = sw .toString ();
1979+ assertEquals ("\" " + idSpace + "a" + idSpace + "\" ,b" + RECORD_SEPARATOR + "ab,c" + RECORD_SEPARATOR , string );
1980+ try (CSVParser parser = CSVParser .parse (string , format )) {
1981+ final List <CSVRecord > records = parser .getRecords ();
1982+ assertEquals (2 , records .size ());
1983+ assertEquals (idSpace + "a" + idSpace , records .get (0 ).get (0 ));
1984+ assertEquals ("b" , records .get (0 ).get (1 ));
1985+ assertEquals ("ab" , records .get (1 ).get (0 ));
1986+ assertEquals ("c" , records .get (1 ).get (1 ));
1987+ }
1988+ }
1989+
19661990 @ Test
19671991 void testRandomDefault () throws Exception {
19681992 doRandom (CSVFormat .DEFAULT , ITERATIONS_FOR_RANDOM_TEST );
0 commit comments