From 1f5c4f62c850b6edd2a72b54e21a923d372bb336 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?St=82phane=20Veyret?= Date: Wed, 1 Jul 2009 14:36:05 +0200 Subject: [PATCH] Fix 0009338: CSV export does not escape all characters Adding escaping of newline in the CVS export --- core/csv_api.php | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/core/csv_api.php b/core/csv_api.php index fa429b0..1777b01 100644 --- a/core/csv_api.php +++ b/core/csv_api.php @@ -53,7 +53,13 @@ # -------------------- # escape a string before writing it to csv file. function csv_escape_string( $p_str ) { - if ( strpos( $p_str, csv_get_separator() ) !== false ) { + $t_escaped = str_split( '"' . csv_get_separator() . csv_get_newline() ); + $t_must_escape = false; + while( ( $t_char = current( $t_escaped ) ) !== false && !$t_must_escape ) { + $t_must_escape = strpos( $p_str, $t_char ) !== false; + next( $t_escaped ); + } + if ( $t_must_escape ) { $p_str = '"' . str_replace( '"', '""', $p_str ) . '"'; } -- 1.6.3.2