From: Happy-melon
Date: Tue, 15 Mar 2011 15:09:49 +0000 (+0000)
Subject: Accept empty square bracket pairs in external links: http://www.example.com?foo[...
X-Git-Tag: 1.31.0-rc.0~31387
X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=9ccbe5f7e44e06dd83fde6d4adc59455418d5bc5;p=lhc%2Fweb%2Fwiklou.git
Accept empty square bracket pairs in external links: example.com?foo[]=bar and [http://www.example.com?foo[]=bar link]. Used for MultiSelect arrays, which feature quite heavily in bugzilla search urls, etc.
---
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index d63c856830..7792e75d17 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -68,7 +68,7 @@ class Parser {
# Constants needed for external link processing
# Everything except bracket, space, or control characters
- const EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F]';
+ const EXT_LINK_URL_CLASS = '(?:[^\]\[<>"\\x00-\\x20\\x7F]|(?:\[\]))';
const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)([^][<>"\\x00-\\x20\\x7F]+)
\\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sx';
@@ -161,7 +161,7 @@ class Parser {
$this->mConf = $conf;
$this->mUrlProtocols = wfUrlProtocols();
$this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
- '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
+ '(?:[^\]\[<>"\x00-\x20\x7F]|\[\])+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
if ( isset( $conf['preprocessorClass'] ) ) {
$this->mPreprocessorClass = $conf['preprocessorClass'];
} elseif ( extension_loaded( 'domxml' ) ) {
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 0d3b806c04..815b54208f 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -975,6 +975,33 @@ External links: wiki links within external link (Bug 3695)
!! end
+!! test
+External links: links containing empty bracket pair []
+!! input
+[http://example.com?parameter[]=foo link]
+!! result
+link
+
+!! end
+
+!! test
+External links: links ending in empty bracket pair []
+!! input
+[http://example.com?parameter[]=foo&option[]]
+!! result
+[1]
+
+!! end
+
+!! test
+External links: bare links ending in empty bracket pair []
+!! input
+http://example.com?parameter[]=foo&option[]
+!! result
+http://example.com?parameter%5B%5D=foo&option%5B%5D
+
+!! end
+
!! test
BUG 787: Links with one slash after the url protocol are invalid
!! input