Handle links with multiple pipes correctly in edit summaries
authorThis, that and the other <at.light@live.com.au>
Sun, 29 Nov 2015 10:30:17 +0000 (21:30 +1100)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 20 Sep 2016 22:15:48 +0000 (15:15 -0700)
Bug: T99346
Change-Id: I459b0027c7703b2379e024d88fab74b17ebb11e9

includes/Linker.php
tests/parser/parserTests.txt

index 8682991..9011f17 100644 (file)
@@ -1311,10 +1311,10 @@ class Linker {
                                :? # ignore optional leading colon
                                ([^\]|]+) # 1. link target; page names cannot include ] or |
                                (?:\|
                                :? # ignore optional leading colon
                                ([^\]|]+) # 1. link target; page names cannot include ] or |
                                (?:\|
-                                       # 2. a pipe-separated substring; only the last is captured
-                                       # Stop matching at | and ]] without relying on backtracking.
-                                       ((?:]?[^\]|])*+)
-                               )*
+                                       # 2. link text
+                                       # Stop matching at ]] without relying on backtracking.
+                                       ((?:]?[^\]])*+)
+                               )?
                                \]\]
                                ([^[]*) # 3. link trail (the text up until the next link)
                        /x',
                                \]\]
                                ([^[]*) # 3. link trail (the text up until the next link)
                        /x',
index 2c8b163..1e511f6 100644 (file)
@@ -20905,6 +20905,26 @@ Id starting with underscore
 
 !! end
 
 
 !! end
 
+!! test
+Edit comment with link with more than one pipe (T99346)
+!! options
+comment
+!! wikitext
+[[Main Page|Many|pipes]]
+!! html
+<a href="/wiki/Main_Page" title="Main Page">Many|pipes</a>
+!! end
+
+!! test
+Complex edit comment with link with more than one pipe (T99346)
+!! options
+comment
+!! wikitext
+Created page with "<noinclude>[[Category:Requests for permissions/Bot|{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}]]</noinclude> === [[User:MineoBot|]] 8=== {{Request for permissions/links|Mineo..."
+!! html
+Created page with &quot;&lt;noinclude&gt;<a href="/index.php?title=Category:Requests_for_permissions/Bot&amp;action=edit&amp;redlink=1" class="new" title="Category:Requests for permissions/Bot (page does not exist)">{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}</a>&lt;/noinclude&gt; === <a href="/index.php?title=User:MineoBot&amp;action=edit&amp;redlink=1" class="new" title="User:MineoBot (page does not exist)">User:MineoBot</a> 8=== {{Request for permissions/links|Mineo...&quot;
+!! end
+
 !! test
 Space normalisation on autocomment (bug 22784)
 !! options
 !! test
 Space normalisation on autocomment (bug 22784)
 !! options