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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function getCatchablePatterns(): array
'|',
'\\*\\*',
'\\*',
'\b(?<!:)[a-z0-9\\.\-+]{2,}:\\/\\/[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*[-a-zA-Z0-9()@%_\\+~#&\\/=]', // standalone hyperlinks
'\b(?<!:)[a-z0-9\\.\-+]{2,}:\\/\\/[-a-zA-Z0-9@:%_\\+.~#?&\\/=]*[-a-zA-Z0-9@%_\\+~#&\\/=]', // standalone hyperlinks
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\TestCase;

use function PHPUnit\Framework\assertEquals;
use function trim;

final class InlineLexerTest extends TestCase
{
Expand Down Expand Up @@ -83,4 +84,37 @@ public static function inlineLexerProvider(): array
],
];
}

#[DataProvider('hyperlinkProvider')]
public function testHyperlinkEndsBeforeParenthesis(string $url): void
{
$input = '(text in parenthesis ' . $url . ').';
$lexer = new InlineLexer();

$lexer->setInput($input);
$lexer->moveNext();

for ($i = 0; $i < 21; $i++) {
$lexer->moveNext();
assertEquals(
trim($input[$i]) === '' ? InlineLexer::WHITESPACE : InlineLexer::WORD,
$lexer->token?->type,
);
assertEquals($input[$i], $lexer->token?->value);
}

$lexer->moveNext();
assertEquals(InlineLexer::HYPERLINK, $lexer->token?->type);
assertEquals($url, $lexer->token?->value);
}

/** @return array<string, array<string>> */
public static function hyperlinkProvider(): array
{
return [
'Url with parenthesis' => ['https://www.test.com'],
'Url with parenthesis and query' => ['https://www.test.com?query=1'],
'Url with parenthesis and query and fragment' => ['https://www.test.com?query=1#fragment'],
];
}
}
Loading