From 415a6ffcc87d6a5ffa3d8979969abeaffbf9f31e Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 5 Nov 2012 11:31:31 +0800 Subject: [PATCH] MDL-36113 - lib: Importing csv entries with empty lines in the middle doesn't throw errors. --- lib/csvlib.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/csvlib.class.php b/lib/csvlib.class.php index c178a25315e..552136a4def 100644 --- a/lib/csvlib.class.php +++ b/lib/csvlib.class.php @@ -105,7 +105,15 @@ class csv_import_reader { // str_getcsv doesn't iterate through the csv data properly. It has // problems with line returns. while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) { - $columns[] = $fgetdata; + // Check to see if we have an empty line. + if (count($fgetdata) == 1) { + if ($fgetdata[0] !== null) { + // The element has data. Add it to the array. + $columns[] = $fgetdata; + } + } else { + $columns[] = $fgetdata; + } } $col_count = 0;