Linker: more consistent whitespace parsing in formatLinksInComment
authorThiemo Kreuz (WMDE) <thiemo.kreuz@wikimedia.de>
Tue, 26 Jun 2018 09:55:21 +0000 (09:55 +0000)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 6 Sep 2018 17:19:32 +0000 (17:19 +0000)
Try to paste and preview this in the wikitext as well as the summary
line: [[:a]] [[ :a]]

The wikitext will show "a a", but the summary line will show "a :a".
This is only a display issue, all 4 links correctly link to the
article [[A]].

Change-Id: I08253a6d0b55b9aa3eace519bbdc1a456400bf84

includes/Linker.php
tests/phpunit/includes/LinkerTest.php

index 0ee6c92..c0959bf 100644 (file)
@@ -1221,6 +1221,7 @@ class Linker {
                return preg_replace_callback(
                        '/
                                \[\[
+                               \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking
                                :? # ignore optional leading colon
                                ([^\]|]+) # 1. link target; page names cannot include ] or |
                                (?:\|
index 4c508e3..b8aecc0 100644 (file)
@@ -294,6 +294,11 @@ class LinkerTest extends MediaWikiLangTestCase {
                                'foo bar [[Special:BlankPage]]',
                                null,
                        ],
+                       [
+                               '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
+                               '[[ :Special:BlankPage]]',
+                               null,
+                       ],
                        [
                                '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
                                "[[Foo'bar]]",