Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -77,6 +77,7 @@ |
78 | 78 | * Show --batch-size option in help of maintenance scripts that support it |
79 | 79 | * (bug 4381) Magic quotes cleaning is not comprehensive, key strings not |
80 | 80 | unescaped |
| 81 | +* (bug 30684) Fix bad escaping in mw.message for inexistent messages (i.e. <key>) |
81 | 82 | |
82 | 83 | === API changes in 1.19 === |
83 | 84 | * (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 @@ |
81 | 81 | }); |
82 | 82 | |
83 | 83 | test( 'mw.message & mw.messages', function() { |
84 | | - expect(16); |
| 84 | + expect(17); |
85 | 85 | |
86 | 86 | ok( mw.messages, 'messages defined' ); |
87 | 87 | ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' ); |
— | — | @@ -113,12 +113,16 @@ |
114 | 114 | var goodbye = mw.message( 'goodbye' ); |
115 | 115 | strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' ); |
116 | 116 | |
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(), '<goodbye>', 'Message.toString returns properly escaped <key> if format is "escaped" and key does not exist' ); |
118 | 120 | }); |
119 | 121 | |
120 | 122 | test( 'mw.msg', function() { |
121 | | - expect(2); |
| 123 | + expect(3); |
122 | 124 | |
| 125 | + ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' ); |
| 126 | + |
123 | 127 | equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' ); |
124 | 128 | equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' ); |
125 | 129 | }); |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -146,8 +146,13 @@ |
147 | 147 | * @return string Message as a string in the current form or <key> if key does not exist. |
148 | 148 | */ |
149 | 149 | toString: function() { |
| 150 | + |
150 | 151 | 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 | + } |
152 | 157 | return '<' + this.key + '>'; |
153 | 158 | } |
154 | 159 | var text = this.map.get( this.key ), |