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
74
74
'| ' ,
75
75
'\\* \\* ' ,
76
76
'\\* ' ,
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
78
78
];
79
79
}
80
80
Original file line number Diff line number Diff line change 17
17
use PHPUnit \Framework \TestCase ;
18
18
19
19
use function PHPUnit \Framework \assertEquals ;
20
+ use function trim ;
20
21
21
22
final class InlineLexerTest extends TestCase
22
23
{
@@ -83,4 +84,37 @@ public static function inlineLexerProvider(): array
83
84
],
84
85
];
85
86
}
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
+ }
86
120
}
You can’t perform that action at this time.
0 commit comments