Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

When importing a CSV file force a trailing new line at EOF (bug #4133) #763

Merged
merged 1 commit into from

3 participants

@slimtim

Fix for bug #4133.

https://sourceforge.net/p/phpmyadmin/bugs/4133/

When importing a CSV file this new code adds a trailing new line at end-of-file if one does not exist. Otherwise you can run into a condition where the last line of the file is skipped by the parser or an error occurs stating, "Invalid format of CSV input on line XX"

@coveralls

Coverage Status

Coverage decreased (-0.01%) when pulling 2e7c024 on slimtim:bug_4133 into 7a6c258 on phpmyadmin:master.

@lem9 lem9 was assigned
@lem9
Owner

Thanks for your contribution.

@lem9 lem9 merged commit 240d37e into from
@whitepiegon whitepiegon referenced this pull request from a commit in whitepiegon/phpmyadmin
@whitepiegon whitepiegon #763 jquery validation feature
Signed-off-by: Aayush Anand <aayushism12@gmail.com>
16fb7d9
@whitepiegon whitepiegon referenced this pull request from a commit in whitepiegon/phpmyadmin
@whitepiegon whitepiegon #763 jquery validation feature2
Signed-off-by: Aayush Anand <aayushism12@gmail.com>
ec40c5c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2013
  1. @slimtim

    When importing a CSV file force a trailing new line at EOF to prevent…

    slimtim authored
    … parsing problems. (bug #4133)
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 0 deletions.
  1. +16 −0 libraries/plugins/import/ImportCsv.class.php
View
16 libraries/plugins/import/ImportCsv.class.php
@@ -259,6 +259,22 @@ public function doImport()
// 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'
Something went wrong with that request. Please try again.