r95999 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95998‎ | r95999 | r96000 >
Date:15:28, 1 September 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Fix bad escaping in mw.message for inexistent messages (bug 30684)

mw.message('some-inexistent-message').escaped() should be &lt;some-inexistent-message&gt; instead of <some-inexistent-message>.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -77,6 +77,7 @@
7878 * Show --batch-size option in help of maintenance scripts that support it
7979 * (bug 4381) Magic quotes cleaning is not comprehensive, key strings not
8080 unescaped
 81+* (bug 30684) Fix bad escaping in mw.message for inexistent messages (i.e. <key>)
8182
8283 === API changes in 1.19 ===
8384 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -80,7 +80,7 @@
8181 });
8282
8383 test( 'mw.message & mw.messages', function() {
84 - expect(16);
 84+ expect(17);
8585
8686 ok( mw.messages, 'messages defined' );
8787 ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
@@ -113,12 +113,16 @@
114114 var goodbye = mw.message( 'goodbye' );
115115 strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' );
116116
117 - equal( goodbye.toString(), '<goodbye>', 'Message.toString returns <key> if key does not exist' );
 117+ equal( goodbye.plain(), '<goodbye>', 'Message.toString returns plain <key> if format is "plain" and key does not exist' );
 118+ // bug 30684
 119+ equal( goodbye.escaped(), '&lt;goodbye&gt;', 'Message.toString returns properly escaped &lt;key&gt; if format is "escaped" and key does not exist' );
118120 });
119121
120122 test( 'mw.msg', function() {
121 - expect(2);
 123+ expect(3);
122124
 125+ ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
 126+
123127 equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
124128 equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' );
125129 });
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -146,8 +146,13 @@
147147 * @return string Message as a string in the current form or <key> if key does not exist.
148148 */
149149 toString: function() {
 150+
150151 if ( !this.map.exists( this.key ) ) {
151 - // Return <key> if key does not exist
 152+ // Use <key> as text if key does not exist
 153+ if ( this.format !== 'plain' ) {
 154+ // format 'escape' and 'parse' need to have the brackets and key html escaped
 155+ return mw.html.escape( '<' + this.key + '>' );
 156+ }
152157 return '<' + this.key + '>';
153158 }
154159 var text = this.map.get( this.key ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r965081.18: MFT r95562, r95570, r95597, r95608, r95647, r95648, r95674, r95790, r95...catrope21:56, 7 September 2011
r102387clean RN 1.19 of bugs merged in 1.18...hashar10:54, 8 November 2011

Comments

#Comment by Krinkle (talk | contribs)   14:22, 2 September 2011

Note: mw.html.escape is called around everything (ie. including the key) as the key might contain special characters as well.

Status & tagging log