From 17b7e7de58d0923fc6419b62f836566c4c6e1888 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 29 Aug 2024 21:32:22 +0200 Subject: [PATCH] Fix invalid url parsing I did not found any specification where an URL can contain parenthesis in the url, nor we do have a test that fails on this case. If we need it anyway we can introduce it later on. But for now this fixes a bug where the fetch of a url is way to gredy. (cherry picked from commit 075539c228d3621bd697b1366e56a47d325dc45c) --- .../RestructuredText/Parser/InlineLexer.php | 2 +- .../tests/unit/Parser/InlineLexerTest.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php b/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php index bebdfa445..94aaf19ba 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php @@ -74,7 +74,7 @@ protected function getCatchablePatterns(): array '|', '\\*\\*', '\\*', - '\b(?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> */ + 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'], + ]; + } }