Skip to content

Commit ed20587

Browse files
committed
[BUGFIX] Make Email detection in lexer more strict
So it does not catch email like expressions in backticks
1 parent a824e13 commit ed20587

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function getCatchablePatterns(): array
5656
return [
5757
'\\\\``', // must be a separate case, as the next pattern would split in "\`" + "`", causing it to become a intepreted text
5858
'\\\\[\s\S]', // Escaping hell... needs escaped slash in regex, but also in php.
59-
'\\S+@\\S+\\.\\S+',
59+
'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}',
6060
'[a-z0-9-]+_{2}', //Inline href.
6161
'[a-z0-9-]+_{1}(?=[\s\.+]|$)', //Inline href.
6262
'``.+?``(?!`)',
@@ -116,7 +116,7 @@ protected function getType(string &$value)
116116
return self::HYPERLINK;
117117
}
118118

119-
if (preg_match('/\\S+@\\S+\\.\\S+/i', $value)) {
119+
if (preg_match('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/i', $value)) {
120120
return self::EMAIL;
121121
}
122122

packages/guides-restructured-text/tests/unit/Parser/InlineLexerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public static function inlineLexerProvider(): array
5252
'css_ and something',
5353
[InlineLexer::NAMED_REFERENCE],
5454
],
55+
'Email' => [
56+
'git@github.com',
57+
[InlineLexer::EMAIL],
58+
],
59+
'Email in backticks' => [
60+
'`git@github.com`',
61+
[InlineLexer::BACKTICK],
62+
],
5563
];
5664
}
5765
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Test</title>
5+
6+
</head>
7+
<body>
8+
<div class="section" id="test">
9+
<h1>Test</h1>
10+
11+
12+
13+
<ul>
14+
<li>Lorem: <code>Ipsum</code></li>
15+
16+
<li>Dolor: <code>git@github.com</code></li>
17+
18+
<li>URL of fork: <code>git@github.com:&lt;your username&gt;/TYPO3CMS-Guide-HowToDocument.git</code></li>
19+
20+
<li>original URL: <code>git@github.com:TYPO3-Documentation/TYPO3CMS-Guide-HowToDocument.git</code></li>
21+
22+
</ul>
23+
24+
</div>
25+
26+
</body>
27+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
====
3+
Test
4+
====
5+
6+
* Lorem: `Ipsum`
7+
* Dolor: `git@github.com`
8+
* URL of fork: `git@github.com:<your username>/TYPO3CMS-Guide-HowToDocument.git`
9+
* original URL: `git@github.com:TYPO3-Documentation/TYPO3CMS-Guide-HowToDocument.git`

0 commit comments

Comments
 (0)