From 9ccbe5f7e44e06dd83fde6d4adc59455418d5bc5 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Tue, 15 Mar 2011 15:09:49 +0000 Subject: [PATCH] Accept empty square bracket pairs in external links: http://www.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. --- includes/parser/Parser.php | 4 ++-- tests/parser/parserTests.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) 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 -- 2.20.1