Fix bad escaping in mw.message for inexistent messages (bug 30684)
authorKrinkle <krinkle@users.mediawiki.org>
Thu, 1 Sep 2011 15:28:28 +0000 (15:28 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Thu, 1 Sep 2011 15:28:28 +0000 (15:28 +0000)
mw.message('some-inexistent-message').escaped() should be &lt;some-inexistent-message&gt; instead of <some-inexistent-message>.

RELEASE-NOTES-1.19
resources/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 805b980..8524624 100644 (file)
@@ -77,6 +77,7 @@ production.
 * Show --batch-size option in help of maintenance scripts that support it
 * (bug 4381) Magic quotes cleaning is not comprehensive, key strings not
   unescaped
+* (bug 30684) Fix bad escaping in mw.message for inexistent messages (i.e. <key>)
 
 === API changes in 1.19 ===
 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
index 86fb82d..cf89e03 100644 (file)
@@ -146,8 +146,13 @@ window.mw = window.mediaWiki = new ( function( $ ) {
                 * @return string Message as a string in the current form or <key> if key does not exist.
                 */
                toString: function() {
+
                        if ( !this.map.exists( this.key ) ) {
-                               // Return <key> if key does not exist
+                               // Use <key> as text if key does not exist
+                               if ( this.format !== 'plain' ) {
+                                       // format 'escape' and 'parse' need to have the brackets and key html escaped
+                                       return mw.html.escape( '<' + this.key + '>' );
+                               }
                                return '<' + this.key + '>';
                        }
                        var     text = this.map.get( this.key ),
index 70e3a22..ffb88b1 100644 (file)
@@ -80,7 +80,7 @@ test( 'mw.config', function() {
 });
 
 test( 'mw.message & mw.messages', function() {
-       expect(16);
+       expect(17);
 
        ok( mw.messages, 'messages defined' );
        ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
@@ -113,11 +113,15 @@ test( 'mw.message & mw.messages', function() {
        var goodbye = mw.message( 'goodbye' );
        strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' );
 
-       equal( goodbye.toString(), '<goodbye>', 'Message.toString returns <key> if key does not exist' );
+       equal( goodbye.plain(), '<goodbye>', 'Message.toString returns plain <key> if format is "plain" and key does not exist' );
+       // bug 30684
+       equal( goodbye.escaped(), '&lt;goodbye&gt;', 'Message.toString returns properly escaped &lt;key&gt; if format is "escaped" and key does not exist' );
 });
 
 test( 'mw.msg', function() {
-       expect(2);
+       expect(3);
+
+       ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
 
        equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
        equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' );