File tree Expand file tree Collapse file tree
src/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -250,7 +250,7 @@ public void print(String value) {
250250 * @param value needs to be escaped and quoted
251251 * @return the value, escaped and quoted
252252 */
253- private static String escapeAndQuote (String value ) {
253+ private String escapeAndQuote (String value ) {
254254 // the initial count is for the preceding and trailing quotes
255255 int count = 2 ;
256256 for (int i = 0 ; i < value .length (); i ++) {
@@ -266,13 +266,15 @@ private static String escapeAndQuote(String value) {
266266 }
267267 }
268268 StringBuffer sb = new StringBuffer (value .length () + count );
269- sb .append ('"' );
269+ sb .append (strategy . getEncapsulator () );
270270 for (int i = 0 ; i < value .length (); i ++) {
271271 char c = value .charAt (i );
272+
273+ if (c == strategy .getEncapsulator ()) {
274+ sb .append ('\\' ).append (c );
275+ continue ;
276+ }
272277 switch (c ) {
273- case '\"' :
274- sb .append ("\\ \" " );
275- break ;
276278 case '\n' :
277279 sb .append ("\\ n" );
278280 break ;
@@ -286,7 +288,7 @@ private static String escapeAndQuote(String value) {
286288 sb .append (c );
287289 }
288290 }
289- sb .append ('"' );
291+ sb .append (strategy . getEncapsulator () );
290292 return sb .toString ();
291293 }
292294
You can’t perform that action at this time.
0 commit comments