Skip to content

Commit a78fdee

Browse files
committed
Update cursor state after parsing
1 parent eec333c commit a78fdee

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Parsers/UrlParser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function getCharacters(): array
3939
*/
4040
public function parse(Cursor $cursor): ?Element
4141
{
42+
$state = $cursor->getState();
43+
4244
$start = $cursor->getPosition();
4345

4446
if ($cursor->getText($start, 3) !== '://') {
@@ -77,6 +79,9 @@ public function parse(Cursor $cursor): ?Element
7779

7880
$position = $this->trimMoreDelimeters($cursor, $start, $end);
7981

82+
$state['position'] = $position['end'];
83+
$cursor->setState($state);
84+
8085
$url = $title = $cursor->getText($position['start'], $position['end'] - $position['start']);
8186

8287
return new UrlElement($title, $url, $position['start'], $position['end']);

tests/AutolinkTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function testAutolinkWithBrackets(): void
9797
$this->assertEquals("{link: {$link3}}", $this->autolink->convert("{link: {$url3}}"));
9898
}
9999

100+
public function testAutolinkWithMultipleLinks(): void
101+
{
102+
$url = 'http://example.com<br>http://example.com<br>http://example.com';
103+
$link = $this->generateLink($url);
104+
105+
$this->assertEquals('<a href="http://example.com">http://example.com</a><br><a href="http://example.com">http://example.com</a><br><a href="http://example.com">http://example.com</a>', $this->autolink->convert($url));
106+
}
107+
100108
public function testAutolinkWithMultipleTrailingPunctuations(): void
101109
{
102110
$url = 'http://example.com';

0 commit comments

Comments
 (0)