@@ -1930,6 +1930,30 @@ void testQuoteValueEndingWithMultiCharacterDelimiterPrefix() throws IOException
19301930 }
19311931 }
19321932
1933+ @ Test
1934+ void testQuoteValueEndingWithSupplementaryDelimiterPrefix () throws IOException {
1935+ // Supplementary code point (surrogate pair) used inside a multi-character delimiter.
1936+ final String clef = new String (Character .toChars (0x1D11E ));
1937+ final CSVFormat format = CSVFormat .DEFAULT .builder ().setDelimiter (clef + clef ).get ();
1938+ final StringWriter sw = new StringWriter ();
1939+ try (CSVPrinter printer = new CSVPrinter (sw , format )) {
1940+ // Value ending in one clef is a straddling prefix of the two-clef delimiter and must be quoted.
1941+ printer .printRecord ("a" + clef , "b" );
1942+ // Value not ending in a delimiter prefix stays unquoted.
1943+ printer .printRecord ("ab" , "c" );
1944+ }
1945+ final String string = sw .toString ();
1946+ assertEquals ("\" a" + clef + "\" " + clef + clef + "b" + RECORD_SEPARATOR + "ab" + clef + clef + "c" + RECORD_SEPARATOR , string );
1947+ try (CSVParser parser = CSVParser .parse (string , format )) {
1948+ final List <CSVRecord > records = parser .getRecords ();
1949+ assertEquals (2 , records .size ());
1950+ assertEquals ("a" + clef , records .get (0 ).get (0 ));
1951+ assertEquals ("b" , records .get (0 ).get (1 ));
1952+ assertEquals ("ab" , records .get (1 ).get (0 ));
1953+ assertEquals ("c" , records .get (1 ).get (1 ));
1954+ }
1955+ }
1956+
19331957 @ Test
19341958 void testQuoteNonNumeric () throws IOException {
19351959 final StringWriter sw = new StringWriter ();
0 commit comments