From 68b849a37bb5d8bf7f54a3e35b9631b28b66b41a Mon Sep 17 00:00:00 2001 From: Susann Sgorzaly Date: Mon, 26 Feb 2018 08:55:51 +0100 Subject: [PATCH] corrected regex to fit all given enclosures. Added test for single enclosure --- src/Csv.php | 2 +- tests/methods/DataRowCountTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Csv.php b/src/Csv.php index 297f463..5f98d79 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -556,7 +556,7 @@ class Csv { $this->_detect_and_remove_sep_row_from_data($data); - $pattern = sprintf('/("[^%s]*")|[^%s]*/i', $this->enclosure, $this->enclosure); + $pattern = sprintf('/(%1$s[^%1$s]*%1$s)/i', $this->enclosure); preg_match_all($pattern, $data, $matches); foreach ($matches[0] as $match) { diff --git a/tests/methods/DataRowCountTest.php b/tests/methods/DataRowCountTest.php index a1fb0e2..693d736 100644 --- a/tests/methods/DataRowCountTest.php +++ b/tests/methods/DataRowCountTest.php @@ -63,4 +63,14 @@ class DataRowCountTest extends TestCase { $this->csv->load_data($sInput); $this->assertEquals(3, $this->csv->getTotalDataRowCount()); } + + + public function testGetTotalRowCountSingleEnclosure() { + $this->csv->heading = false; + $this->csv->enclosure = "'"; + $sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\'c\r\nd\'"; + $this->csv->load_data($sInput); + $this->assertEquals(3, $this->csv->getTotalDataRowCount()); + } + }