File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
packages/guides-restructured-text
src/RestructuredText/Parser Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ protected function getCatchablePatterns(): array
7474 '| ' ,
7575 '\\* \\* ' ,
7676 '\\* ' ,
77- '\b(?<!:)[a-z0-9 \\.\-+]{2,}: \\/ \\/[-a-zA-Z0-9() @:%_ \\+.~#?& \\/=]*[-a-zA-Z0-9() @%_ \\+~#& \\/=] ' , // standalone hyperlinks
77+ '\b(?<!:)[a-z0-9 \\.\-+]{2,}: \\/ \\/[-a-zA-Z0-9@:%_ \\+.~#?& \\/=]*[-a-zA-Z0-9@%_ \\+~#& \\/=] ' , // standalone hyperlinks
7878 ];
7979 }
8080
Original file line number Diff line number Diff line change 1717use PHPUnit \Framework \TestCase ;
1818
1919use function PHPUnit \Framework \assertEquals ;
20+ use function trim ;
2021
2122final class InlineLexerTest extends TestCase
2223{
@@ -83,4 +84,37 @@ public static function inlineLexerProvider(): array
8384 ],
8485 ];
8586 }
87+
88+ #[DataProvider('hyperlinkProvider ' )]
89+ public function testHyperlinkEndsBeforeParenthesis (string $ url ): void
90+ {
91+ $ input = '(text in parenthesis ' . $ url . '). ' ;
92+ $ lexer = new InlineLexer ();
93+
94+ $ lexer ->setInput ($ input );
95+ $ lexer ->moveNext ();
96+
97+ for ($ i = 0 ; $ i < 21 ; $ i ++) {
98+ $ lexer ->moveNext ();
99+ assertEquals (
100+ trim ($ input [$ i ]) === '' ? InlineLexer::WHITESPACE : InlineLexer::WORD ,
101+ $ lexer ->token ?->type,
102+ );
103+ assertEquals ($ input [$ i ], $ lexer ->token ?->value);
104+ }
105+
106+ $ lexer ->moveNext ();
107+ assertEquals (InlineLexer::HYPERLINK , $ lexer ->token ?->type);
108+ assertEquals ($ url , $ lexer ->token ?->value);
109+ }
110+
111+ /** @return array<string, array<string>> */
112+ public static function hyperlinkProvider (): array
113+ {
114+ return [
115+ 'Url with parenthesis ' => ['https://www.test.com ' ],
116+ 'Url with parenthesis and query ' => ['https://www.test.com?query=1 ' ],
117+ 'Url with parenthesis and query and fragment ' => ['https://www.test.com?query=1#fragment ' ],
118+ ];
119+ }
86120}
You can’t perform that action at this time.
0 commit comments