(bug 36151) mw.Title: Don't limit extension in title parsing.
authorMatmaRex <matma.rex@gmail.com>
Sat, 29 Sep 2012 13:32:49 +0000 (15:32 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Sat, 29 Sep 2012 23:24:53 +0000 (01:24 +0200)
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
resources/mediawiki/mediawiki.Title.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js

index e4dd207..3e68abd 100644 (file)
@@ -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.
index 9e030fa..33cca58 100644 (file)
@@ -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] !== '' ) {
index 6360925..a736e12 100644 (file)
@@ -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