r84022 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84021‎ | r84022 | r84023 >
Date:15:09, 15 March 2011
Author:happy-melon
Status:reverted (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -68,7 +68,7 @@
6969
7070 # Constants needed for external link processing
7171 # Everything except bracket, space, or control characters
72 - const EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F]';
 72+ const EXT_LINK_URL_CLASS = '(?:[^\]\[<>"\\x00-\\x20\\x7F]|(?:\[\]))';
7373 const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)([^][<>"\\x00-\\x20\\x7F]+)
7474 \\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sx';
7575
@@ -161,7 +161,7 @@
162162 $this->mConf = $conf;
163163 $this->mUrlProtocols = wfUrlProtocols();
164164 $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
165 - '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
 165+ '(?:[^\]\[<>"\x00-\x20\x7F]|\[\])+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
166166 if ( isset( $conf['preprocessorClass'] ) ) {
167167 $this->mPreprocessorClass = $conf['preprocessorClass'];
168168 } elseif ( extension_loaded( 'domxml' ) ) {
Index: trunk/phase3/tests/parser/parserTests.txt
@@ -976,6 +976,33 @@
977977 !! end
978978
979979 !! test
 980+External links: links containing empty bracket pair []
 981+!! input
 982+[http://example.com?parameter[]=foo link]
 983+!! result
 984+<p><a rel="nofollow" class="external text" href="http://example.com?parameter%5B%5D=foo">link</a>
 985+</p>
 986+!! end
 987+
 988+!! test
 989+External links: links ending in empty bracket pair []
 990+!! input
 991+[http://example.com?parameter[]=foo&option[]]
 992+!! result
 993+<p><a rel="nofollow" class="external autonumber" href="http://example.com?parameter%5B%5D=foo&amp;option%5B%5D">[1]</a>
 994+</p>
 995+!! end
 996+
 997+!! test
 998+External links: bare links ending in empty bracket pair []
 999+!! input
 1000+http://example.com?parameter[]=foo&option[]
 1001+!! result
 1002+<p><a rel="nofollow" class="external free" href="http://example.com?parameter%5B%5D=foo&amp;option%5B%5D">http://example.com?parameter%5B%5D=foo&amp;option%5B%5D</a>
 1003+</p>
 1004+!! end
 1005+
 1006+!! test
9801007 BUG 787: Links with one slash after the url protocol are invalid
9811008 !! input
9821009 http:/example.com

Follow-up revisions

RevisionCommit summaryAuthorDate
r89088Rv r84022 for now: crashes PHP on large url strings (bug29197), which is a na...happy-melon09:32, 29 May 2011
r89208revert r84022 parser tests (code reverted by r89088)...hashar06:17, 31 May 2011

Comments

#Comment by Raymond (talk | contribs)   15:26, 15 March 2011

Thanks for this fix. Would it be possible to allow square brackets with content too? See translatewiki:User:Raymond/Square brackets for an example.

#Comment by Raymond (talk | contribs)   15:29, 15 March 2011

BTW: This is bug 3695.

#Comment by MaxSem (talk | contribs)   08:04, 29 May 2011

Causes bug 29197.

Status & tagging log