Skip to content

Commit 073ca2a

Browse files
authored
Merge pull request #25 from KamilBalwierz/master
Support parsing multiline values starting with quoted newline
2 parents 6b22819 + 29769b5 commit 073ca2a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Decoder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public function handleData($data)
110110
// this looks like a multiline value, so only remember offset and wait for next newline
111111
$last = \substr(\end($data), -1);
112112
\reset($data);
113-
if ($last === "\n" && ($newline === 1 || $this->buffer[$newline - 1] !== $this->enclosure)) {
113+
$edgeCase = \substr($this->buffer, $newline - 2, 3);
114+
if ($last === "\n" && ($newline === 1 || $this->buffer[$newline - 1] !== $this->enclosure || $edgeCase === $this->delimiter . $this->enclosure . "\n")) {
114115
$this->offset = $newline + 1;
115116
continue;
116117
}

tests/DecoderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public function testEmitDataStringEndsWithNewlineWillForward()
8686
$this->input->emit('data', array("\"hello\n\"\n"));
8787
}
8888

89+
public function testEmitDataStringWithNewLineAsStartOfFieldWillForward()
90+
{
91+
$this->decoder->on('data', $this->expectCallableOnceWith(array("one", "\ntwo\n", "three")));
92+
93+
$this->input->emit('data', array("one,\"\ntwo\n\",three\n"));
94+
}
95+
8996
public function testEmitDataStringOnlyNewlineWillForward()
9097
{
9198
$this->decoder->on('data', $this->expectCallableOnceWith(array("\n")));

0 commit comments

Comments
 (0)