Skip to content

Commit

Permalink
Merge 5b3d856 into a7d20bb
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherch committed Mar 3, 2017
2 parents a7d20bb + 5b3d856 commit ccb1f36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/KzykHys/CsvParser/Iterator/CsvIterator.php
Expand Up @@ -85,19 +85,20 @@ public function current()
// loop over the columns
foreach ($tokens as $value) {
$value = preg_replace('/"(\r\n|\r|\n)*$/', '"', $value);
$lastChar = substr($value, -1);
$lastTwoChars = substr($value, -2);

// check the first letter is 'enclosure' or not
if (substr($value, 0, 1) == $this->option['enclosure']) {
// check the last letter is 'enclosure'
if (substr($value, -1) == $this->option['enclosure']) {
if ($lastChar == $this->option['enclosure'] && $lastTwoChars != '\"') {
$this->processEnclosedField($value, $this->option);
} else {
$this->processContinuousField($value, $this->option);
}

} else { // first letter is NOT 'enclosure'
// check the last letter is 'enclosure'
if(substr($value, -1) == $this->option['enclosure']) {
if ($lastChar == $this->option['enclosure'] && $lastTwoChars != '\"') {
$this->processClosingField($value, $this->option);
} else {
$this->processField($value, $this->option);
Expand Down
17 changes: 17 additions & 0 deletions test/KzykHys/CsvParser/CsvParserTest.php
Expand Up @@ -63,6 +63,23 @@ public function testCompareResultsFromFileAndString($name, array $files, $out)
$this->assertEquals($out, $results['CR'], $name . '(CR)');
}

public function testMultiLineWithQuotationAtEndOfLine()
{
//given
$csvString = <<<EOF
"key","a","b","c"
"abcd","<div class=\"class\"
href=\"/url\"
>end</div>","asd",""
EOF;

//when
$parsedCsv = CsvParser::fromString($csvString)->parse();

//then
$this->assertEquals('<div class=\"class\" href=\"/url\">end</div>',$parsedCsv[1][1]);
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down

0 comments on commit ccb1f36

Please sign in to comment.