View Issue Details

IDProjectCategoryView StatusLast Update
0010420mantisbtcsvpublic2009-06-23 15:26
Reporterkesterhabermann Assigned Tograngeway  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformanyOSanyOS Versionany
Product Version1.1.7 
Fixed in Version1.2.0rc1 
Summary0010420: Custom fields with newline break CSV export
Description

Multiline entries in custom fields break CSV export as the newlines appear in the CSV.

The following change to "csv_export.php" and "core/csv_api.php" will remove the newlines in the CSV export for all fields:

--- mantisbt-1.1.7.orig/csv_export.php 2009-04-20 15:14:00.000000000 +0200
+++ mantisbt-1.1.7/csv_export.php 2009-04-27 11:38:07.352036000 +0200
@@ -116,11 +117,7 @@
helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
$t_value = ob_get_clean();

  • if ( strstr( $t_value, $t_sep ) !== false ) {

  • $t_value = '"' . $t_value . '"';

  • }

  • echo $t_value;

  • echo csv_escape_string($t_value);
    } else {
    $t_function = 'csvformat' . $t_column;
    echo $t_function( $t_row[ $t_column ] );
    --- mantisbt-1.1.7.orig/core/csv_api.php 2009-04-20 15:14:00.000000000 +0200
    +++ mantisbt-1.1.7/core/csv_api.php 2009-04-27 11:23:37.844829000 +0200
    @@ -57,6 +57,9 @@
    $p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
    }

  • $p_str = str_replace("\n", '', $p_str);

  • $p_str = str_replace("\r", '', $p_str);

  •         return $p_str;
    }
TagsNo tags attached.
Attached Files
mantisbt-1.1.7-csv.patch (937 bytes)   
--- mantisbt-1.1.7.orig/csv_export.php	2009-04-20 15:14:00.000000000 +0200
+++ mantisbt-1.1.7/csv_export.php	2009-04-27 14:06:47.845381000 +0200
@@ -116,11 +116,7 @@
 				helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
 				$t_value = ob_get_clean();
 
-				if ( strstr( $t_value, $t_sep ) !== false ) {
-					$t_value = '"' . $t_value . '"';
-				}
-
-				echo $t_value;
+				echo csv_escape_string($t_value);
 			} else {
 				$t_function = 'csv_format_' . $t_column;
 				echo $t_function( $t_row[ $t_column ] );
--- mantisbt-1.1.7.orig/core/csv_api.php	2009-04-20 15:14:00.000000000 +0200
+++ mantisbt-1.1.7/core/csv_api.php	2009-04-27 11:23:37.844829000 +0200
@@ -57,6 +57,9 @@
 			$p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
 		}
 
+        $p_str =  str_replace("\n", '', $p_str);
+        $p_str =  str_replace("\r", '', $p_str);
+
 		return $p_str;
 	}
 
mantisbt-1.1.7-csv.patch (937 bytes)   

Activities

grangeway

grangeway

2009-05-23 12:27

reporter   ~0021890

Partial commit of your patch

in 1.2, it looks like csv_escape_string has been modified to quote strings containing new line characters

Paul

kesterhabermann

kesterhabermann

2009-06-12 05:51

reporter   ~0022113

Still broken in 1.1.8.