-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
This is:
- [x] a bug report
- [ ] a feature request
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?
<?php
require __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 = new PhpOffice\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.