Merge "core: getTitle: Return undefined for non URI links"

This commit is contained in:
jenkins-bot 2015-04-22 14:14:15 +00:00 committed by Gerrit Code Review
commit 8e694d13b7
2 changed files with 12 additions and 3 deletions

View file

@ -155,8 +155,14 @@
* @return {string|undefined}
*/
mw.popups.getTitle = function ( href ) {
var title, titleRegex, matches,
var title, titleRegex, matches, linkHref;
// Skip every URI that mw.Uri cannot parse
try {
linkHref = new mw.Uri( href );
} catch ( e ) {
return undefined;
}
// External links
if ( linkHref.host !== location.hostname ) {

View file

@ -9,7 +9,7 @@
QUnit.test( 'getTitle', function ( assert ) {
var cases, i, expected, actual;
QUnit.expect( 10 );
QUnit.expect( 11 );
cases = [
[ '/wiki/Foo', 'Foo' ],
[ '/wiki/Foo#Bar', 'Foo' ],
@ -20,7 +20,10 @@
[ '/w/Foo?title=Foo&action=edit', undefined ],
[ '/w/index.php?title=%E6%B8%AC%E8%A9%A6', '測試' ],
[ '/w/index.php?oldid=1', undefined ],
[ '/Foo', undefined ]
[ '/Foo', undefined ],
/*jshint -W107 */
[ 'javascript:void(0);', undefined ]
/*jshint +W107 */
];
for ( i = 0; i < cases.length; i++ ) {