Fix parsing of large CSV files (bug #1456331).
This commit is contained in:
@@ -10,6 +10,7 @@ $Source$
|
|||||||
#1467620).
|
#1467620).
|
||||||
* libraries/Config.class.php: Better check for server system (patch
|
* libraries/Config.class.php: Better check for server system (patch
|
||||||
#1462738).
|
#1462738).
|
||||||
|
* libraries/import/csv.php: Fix parsing of large CSV files (bug #1456331).
|
||||||
|
|
||||||
2006-04-09 Marc Delisle <lem9@users.sourceforge.net>
|
2006-04-09 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* tbl_replace.php, libraries/dbi/mysqli.dbi.lib.php: bug #1255923,
|
* tbl_replace.php, libraries/dbi/mysqli.dbi.lib.php: bug #1255923,
|
||||||
|
@@ -129,13 +129,14 @@ if ($plugin_param == 'table') {
|
|||||||
$ch = $buffer[$i];
|
$ch = $buffer[$i];
|
||||||
while ($i < $len) {
|
while ($i < $len) {
|
||||||
// Deadlock protection
|
// Deadlock protection
|
||||||
if ($lasti == $i) {
|
if ($lasti == $i && $lastlen == $len) {
|
||||||
$message = sprintf($strInvalidCSVFormat, $line);
|
$message = sprintf($strInvalidCSVFormat, $line);
|
||||||
$show_error_header = TRUE;
|
$show_error_header = TRUE;
|
||||||
$error = TRUE;
|
$error = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$lasti = $i;
|
$lasti = $i;
|
||||||
|
$lastlen = $len;
|
||||||
|
|
||||||
// This can happen with auto EOL and \r at the end of buffer
|
// This can happen with auto EOL and \r at the end of buffer
|
||||||
if (!$csv_finish) {
|
if (!$csv_finish) {
|
||||||
@@ -151,6 +152,7 @@ if ($plugin_param == 'table') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab one field
|
// Grab one field
|
||||||
|
$fallbacki = $i;
|
||||||
if ($ch == $csv_enclosed) {
|
if ($ch == $csv_enclosed) {
|
||||||
$need_end = TRUE;
|
$need_end = TRUE;
|
||||||
if ($i == $len - 1) {
|
if ($i == $len - 1) {
|
||||||
@@ -183,12 +185,15 @@ if ($plugin_param == 'table') {
|
|||||||
$ch = $buffer[$i];
|
$ch = $buffer[$i];
|
||||||
}
|
}
|
||||||
if ($fail) {
|
if ($fail) {
|
||||||
|
$i = $fallbacki;
|
||||||
|
$ch = $buffer[$i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$values[] = $value;
|
|
||||||
// Need to strip trailing enclosing char?
|
// Need to strip trailing enclosing char?
|
||||||
if ($need_end && $ch == $csv_enclosed) {
|
if ($need_end && $ch == $csv_enclosed) {
|
||||||
if ($i == $len - 1) {
|
if ($i == $len - 1) {
|
||||||
|
$i = $fallbacki;
|
||||||
|
$ch = $buffer[$i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
@@ -201,11 +206,15 @@ if ($plugin_param == 'table') {
|
|||||||
// Go to next char
|
// Go to next char
|
||||||
if ($ch == $csv_terminated) {
|
if ($ch == $csv_terminated) {
|
||||||
if ($i == $len - 1) {
|
if ($i == $len - 1) {
|
||||||
|
$i = $fallbacki;
|
||||||
|
$ch = $buffer[$i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
$ch = $buffer[$i];
|
$ch = $buffer[$i];
|
||||||
}
|
}
|
||||||
|
// If everything went okay, store value
|
||||||
|
$values[] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of line
|
// End of line
|
||||||
|
Reference in New Issue
Block a user