r94346 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94345‎ | r94346 | r94347 >
Date:13:32, 12 August 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
(bug 30236) Links like [[//example.com Link text]] were parsed as an internal link rather than an external link surrounded by brackets, like [[http://example.com Link text]]. Was caused by another pointless \b directly preceding wfUrlProtocols() in a regex. Also add a parser test for the [[http://example.com Link text]] case (the existing test only covered [[http://example.com]]) and add protocol-relative counterparts for both tests.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -2197,6 +2197,34 @@
21982198 </p>
21992199 !! end
22002200
 2201+!! test
 2202+Plain link to URL with link text
 2203+!! input
 2204+[[http://www.example.com Link text]]
 2205+!! result
 2206+<p>[<a rel="nofollow" class="external text" href="http://www.example.com">Link text</a>]
 2207+</p>
 2208+!! end
 2209+
 2210+!! test
 2211+Plain link to protocol-relative URL
 2212+!! input
 2213+[[//www.example.com]]
 2214+!! result
 2215+<p>[<a rel="nofollow" class="external autonumber" href="https://www.mediawiki.org//www.example.com">[1]</a>]
 2216+</p>
 2217+!! end
 2218+
 2219+!! test
 2220+Plain link to protocol-relative URL with link text
 2221+!! input
 2222+[[//www.example.com Link text]]
 2223+!! result
 2224+<p>[<a rel="nofollow" class="external text" href="https://www.mediawiki.org//www.example.com">Link text</a>]
 2225+</p>
 2226+!! end
 2227+
 2228+
22012229 # I'm fairly sure the expected result here is wrong.
22022230 # We want these to be URL links, not pseudo-pages with URLs for titles....
22032231 # However the current output is also pretty screwy.
Index: trunk/phase3/includes/parser/Parser.php
@@ -1896,7 +1896,7 @@
18971897 # Don't allow internal links to pages containing
18981898 # PROTO: where PROTO is a valid URL protocol; these
18991899 # should be external links.
1900 - if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
 1900+ if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
19011901 $s .= $prefix . '[[' . $line ;
19021902 wfProfileOut( __METHOD__."-misc" );
19031903 continue;

Sign-offs

UserFlagDate
Hazard-SJinspected03:08, 13 August 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r94446MFT to REL1_18:...hashar09:27, 14 August 2011
r945621.17wmf1: MFT r93711, r94346, r94369, r94376, r94404, r94502, r94509, r94511catrope20:30, 15 August 2011

Comments

#Comment by Krinkle (talk | contribs)   13:27, 14 August 2011

Regarding bug 30236, perhaps include a test for Template:Fullurl: as well ? Not sure how that behaves (ie. parser test for

[{{fullurl:Foo|bar=baz}} quux]

with protocol-relative)

#Comment by Catrope (talk | contribs)   13:29, 14 August 2011

There are no tests for fullurl at all (not even for its regular modus operandi), and I don't know of any way to control $wgServer in a parser test.

Status & tagging log