From 2e7c024df64fdcc4154b560715d97a77c9af159e Mon Sep 17 00:00:00 2001 From: slimtim Date: Wed, 20 Nov 2013 16:43:01 -0500 Subject: [PATCH] When importing a CSV file force a trailing new line at EOF to prevent parsing problems. (bug #4133) --- libraries/plugins/import/ImportCsv.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index 64e2eae85c..d17d7390ae 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -259,6 +259,22 @@ class ImportCsv extends AbstractImportCsv // Append new data to buffer $buffer .= $data; unset($data); + + // Force a trailing new line at EOF to prevent parsing problems + if ($finished && $buffer) { + $finalch = substr($buffer, -1); + if ($csv_new_line == 'auto' + && $finalch != "\r" + && $finalch != "\n" + ) { + $buffer .= "\n"; + } elseif ($csv_new_line != 'auto' + && $finalch != $csv_new_line + ) { + $buffer .= $csv_new_line; + } + } + // Do not parse string when we're not at the end // and don't have new line inside if (($csv_new_line == 'auto'