From 41b95c15422a3a2cc4dc35dd25214c1b07353bb1 Mon Sep 17 00:00:00 2001 From: oleibman Date: Sun, 24 May 2020 03:57:39 -0700 Subject: [PATCH] CSV Sample File Was Miscoded (#1489) File author erroneously assumed that backslash was used to escape quotes in CSV; in fact, doubling the quote is used for escape. The test still worked, but mainly because the content of the cell with the escape wasn't tested. The file is now fixed, and a new test added. --- tests/PhpSpreadsheetTests/Reader/CsvTest.php | 31 +++++++++++++++++ .../Reader/CSV/line_break_escaped_32le.csv | Bin 0 -> 2120 bytes ...break_in_enclosure_with_escaped_quotes.csv | 32 +++++++++--------- 3 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 tests/data/Reader/CSV/line_break_escaped_32le.csv diff --git a/tests/PhpSpreadsheetTests/Reader/CsvTest.php b/tests/PhpSpreadsheetTests/Reader/CsvTest.php index cb2b6196..e4ccd931 100644 --- a/tests/PhpSpreadsheetTests/Reader/CsvTest.php +++ b/tests/PhpSpreadsheetTests/Reader/CsvTest.php @@ -200,6 +200,37 @@ EOF; self::assertEquals($expected, $sheet->getCell('B3')->getValue()); } + public function testLineBreakEscape(): void + { + $reader = new Csv(); + $spreadsheet = $reader->load('tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv'); + $sheet = $spreadsheet->getActiveSheet(); + $expected = <<getCell('B3')->getValue()); + } + + public function testUtf32LineBreakEscape(): void + { + $reader = new Csv(); + $reader->setInputEncoding('UTF-32LE'); + $spreadsheet = $reader->load('tests/data/Reader/CSV/line_break_escaped_32le.csv'); + $sheet = $spreadsheet->getActiveSheet(); + $expected = <<getCell('B3')->getValue()); + } + public function testSeparatorLine(): void { $reader = new Csv(); diff --git a/tests/data/Reader/CSV/line_break_escaped_32le.csv b/tests/data/Reader/CSV/line_break_escaped_32le.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e0f0243ecadcb1773684cf9c78913d7dbcc310a GIT binary patch literal 2120 zcmeH_NeTin5Jj{06v4IV-mP14A?*R$S)6CQz3+hqjo=B);?YUv*H2ZtMk%El_OO5s z4B!YSc!9AAj9~~Zs6hP{ZlIfX@CGy6u+9Jg literal 0 HcmV?d00001 diff --git a/tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv b/tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv index e84db1b5..01ce36a6 100644 --- a/tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv +++ b/tests/data/Reader/CSV/line_break_in_enclosure_with_escaped_quotes.csv @@ -1,21 +1,21 @@ Name,Copy,URL -Test,"This is a \"test csv file\" -with both \"line breaks\" -and \"escaped -quotes\" that breaks +Test,"This is a ""test csv file"" +with both ""line breaks"" +and ""escaped +quotes"" that breaks the delimiters",http://google.com -Test,"This is a \"test csv file\" -with both \"line breaks\" -and \"escaped -quotes\" that breaks +Test,"This is a ""test csv file"" +with both ""line breaks"" +and ""escaped +quotes"" that breaks the delimiters",http://google.com -Test,"This is a \"test csv file\" -with both \"line breaks\" -and \"escaped -quotes\" that breaks +Test,"This is a ""test csv file"" +with both ""line breaks"" +and ""escaped +quotes"" that breaks the delimiters",http://google.com -Test,"This is a \"test csv file\" -with both \"line breaks\" -and \"escaped -quotes\" that breaks +Test,"This is a ""test csv file"" +with both ""line breaks"" +and ""escaped +quotes"" that breaks the delimiters",http://google.com