From d4f2c0e8f76a7634fce1631669f4ce037965d8b5 Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Sat, 29 Sep 2012 15:32:49 +0200 Subject: [PATCH] (bug 36151) mw.Title: Don't limit extension in title parsing. This allows for e.g. "*.properties" files. Previously, the extension could be no more than 5 characters. If it was, it was considered as not having any extension (part of the main title text). Change-Id: Ib27792b661666ac5f704eeaaadcdd9668dd81b56 --- RELEASE-NOTES-1.20 | 1 + resources/mediawiki/mediawiki.Title.js | 4 ++-- .../mediawiki/mediawiki.Title.test.js | 23 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index e4dd2075f6..3e68abd06d 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -248,6 +248,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * (bug 40214) Category pages no longer use deprecated "width" HTML attribute. * (bug 39941) Add missing stylesheets to the installer pages * In HTML5 mode, allow new input element types values (such as color, range..) +* (bug 36151) mw.Title: Don't limit extension in title parsing. === API changes in 1.20 === * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API. diff --git a/resources/mediawiki/mediawiki.Title.js b/resources/mediawiki/mediawiki.Title.js index 9e030fad73..33cca585bf 100644 --- a/resources/mediawiki/mediawiki.Title.js +++ b/resources/mediawiki/mediawiki.Title.js @@ -132,7 +132,7 @@ var setAll = function ( title, s ) { // In normal browsers the match-array contains null/undefined if there's no match, // IE returns an empty string. - var matches = s.match( /^(?:([^:]+):)?(.*?)(?:\.(\w{1,5}))?$/ ), + var matches = s.match( /^(?:([^:]+):)?(.*?)(?:\.(\w+))?$/ ), ns_match = getNsIdByName( matches[1] ); // Namespace must be valid, and title must be a non-empty string. @@ -160,7 +160,7 @@ var setNameAndExtension = function ( title, raw ) { // In normal browsers the match-array contains null/undefined if there's no match, // IE returns an empty string. - var matches = raw.match( /^(?:)?(.*?)(?:\.(\w{1,5}))?$/ ); + var matches = raw.match( /^(?:)?(.*?)(?:\.(\w+))?$/ ); // Title must be a non-empty string. if ( typeof matches[1] === 'string' && matches[1] !== '' ) { diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js index 63609258a7..a736e121b0 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js @@ -146,7 +146,26 @@ QUnit.test( 'toString / toText', 2, function ( assert ) { assert.equal( title.toText(), title.getPrefixedText() ); }); -QUnit.test( 'Exists', 3, function ( assert ) { +QUnit.test( 'getExtension', 7, function ( assert ) { + + function extTest( pagename, ext, description ) { + var title = new mw.Title( pagename ); + assert.equal( title.getExtension(), ext, description || pagename ); + } + + extTest( 'MediaWiki:Vector.js', 'js' ); + extTest( 'User:Example/common.css', 'css' ); + extTest( 'File:Example.longextension', 'longextension', 'Extension parsing not limited (bug 36151)' ); + extTest( 'Example/information.json', 'json', 'Extension parsing not restricted from any namespace' ); + extTest( 'Foo.', null, 'Trailing dot is not an extension' ); + extTest( 'Foo..', null, 'Trailing dots are not an extension' ); + extTest( 'Foo.a.', null, 'Page name with dots and ending in a dot does not have an extension' ); + + // @broken: Throws an exception + // extTest( '.NET', null, 'Leading dot is (or is not?) an extension' ); +}); + +QUnit.test( 'exists', 3, function ( assert ) { var title; // Empty registry, checks default to null @@ -165,7 +184,7 @@ QUnit.test( 'Exists', 3, function ( assert ) { }); -QUnit.test( 'Url', 2, function ( assert ) { +QUnit.test( 'getUrl', 2, function ( assert ) { var title; // Config -- 2.20.1