You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When required, the backslash should be treated as a normal character and not parsed as an escape character.
What is the current behavior?
The backslash acts as an escape character, so when at the end of a cell/field it escapes the closing quote and merges cells/lines.
What are the steps to reproduce?
<?phprequire__DIR__ . '/vendor/autoload.php';
// CSV file with backslash at end of field$contents = '"test field\"' . "\n" . '"another field"';
$filename = __DIR__ . '/test.csv';
file_put_contents($filename, $contents);
// Create a new reader$reader = newPhpOffice\PhpSpreadsheet\Reader\Csv;
$spreadsheet = $reader->load($filename);
var_dump($spreadsheet->getActiveSheet()->getCell('A1')->getValue());
Output:
string(27) "test field\"
another field""
I know the backslash is commonly used as an escape character, but it would be good to at least have an option of turning this off, maybe with a $reader->setEscaping(false) method call. I'm currently dealing with third-party CSVs which contain backslashes (a poor design choice, but considering there's no universal standard I think it's perfectly valid).
RFC 4180 makes no mention of backslashes, using instead a quote character to escape quote characters.
Happy to put together a pull request if this change is deemed worthwhile.
The text was updated successfully, but these errors were encountered:
This seems to make sense. As you probably figured out we use PHP native fgetcsv and we don't expose its $escape parameter. So we you can create a PR for that is covered with unit tests, I'll merged it.
This is:
What is the expected behavior?
When required, the backslash should be treated as a normal character and not parsed as an escape character.
What is the current behavior?
The backslash acts as an escape character, so when at the end of a cell/field it escapes the closing quote and merges cells/lines.
What are the steps to reproduce?
Output:
I know the backslash is commonly used as an escape character, but it would be good to at least have an option of turning this off, maybe with a
$reader->setEscaping(false)
method call. I'm currently dealing with third-party CSVs which contain backslashes (a poor design choice, but considering there's no universal standard I think it's perfectly valid).RFC 4180 makes no mention of backslashes, using instead a quote character to escape quote characters.
Happy to put together a pull request if this change is deemed worthwhile.
The text was updated successfully, but these errors were encountered: