Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect handling of single/double quotes and newlines #8

Open
cronfy opened this issue Mar 17, 2016 · 0 comments
Open

incorrect handling of single/double quotes and newlines #8

cronfy opened this issue Mar 17, 2016 · 0 comments

Comments

@cronfy
Copy link

cronfy commented Mar 17, 2016

Script produces incorrect csv when parsing dump with single/double quotes and newlines. Example:

INSERT INTO `test` VALUES ('single quote \' test','double quote \" test','newline \n test');

After converting we have:

'single quote ' test',"double quote "" test",newline n test

Newline is obviously disappeared, and if we parse it with php fgetcsv(), we'll see incorrect single quotes:

$f = fopen('x.csv', 'r');
$a = fgetcsv($f);

foreach ($a as $v) {
        echo "[$v]\n";
}
$ php ./test.php 
['single quote ' test']
[double quote " test]
[newline n test]

Errors here:

  1. First entry should be without surrounding single quotes.
  2. Third entry must contain newline instead of just "n".

Expected result

single quote ' test,"double quote "" test","newline
test"

Note that there should be 2 lines of text for single csv entry, containing newline. First entry (with single quote) isn't quoted at all. I created this CSV with LibreOffice Calc, and it is parsed with php correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant