Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PatternIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getIterator(): Iterator
}

if (strlen($matches[0]) === 0) {
break 2;
break;
}

yield $matches;
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/PatternIteratorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,20 @@ class PatternIteratorTest extends TestCase
}


public function testZeroLengthMatchMidBufferLoadsMoreData(): void
{
// Pattern matches exactly 3 chars, or empty. When only 1 char remains in the
// buffer but the stream has more data, the empty match mid-buffer must not abort;
// loading the next chunk makes the 3-char alternative succeed.
$iter = new PatternIterator($this->stream('abXY', 'Zmore'), '~.{3}|~A');
$results = $this->collect($iter);
Assert::count(3, $results);
Assert::same('abX', $results[0][0]);
Assert::same('YZm', $results[1][0]);
Assert::same('ore', $results[2][0]);
}


public function testZeroLengthMatchAcrossChunks(): void
{
$pattern = '~\s*(?:(?<query>[^;]+);|\z)~As';
Expand Down