r82099 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82098‎ | r82099 | r82100 >
Date:00:54, 14 February 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
* (bug 25571) Xml::encodeJsVar now passes floats natively instead of converting to strings

Added unit test cases for int, float, and strings that look like int or float.
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/XmlTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/XmlTest.php
@@ -248,4 +248,36 @@
249249 'encodeJsVar() with object'
250250 );
251251 }
 252+
 253+ function testEncodeJsVarInt() {
 254+ $this->assertEquals(
 255+ '123456',
 256+ Xml::encodeJsVar( 123456 ),
 257+ 'encodeJsVar() with int'
 258+ );
 259+ }
 260+
 261+ function testEncodeJsVarFloat() {
 262+ $this->assertEquals(
 263+ '1.23456',
 264+ Xml::encodeJsVar( 1.23456 ),
 265+ 'encodeJsVar() with float'
 266+ );
 267+ }
 268+
 269+ function testEncodeJsVarIntString() {
 270+ $this->assertEquals(
 271+ '"123456"',
 272+ Xml::encodeJsVar( '123456' ),
 273+ 'encodeJsVar() with int-like string'
 274+ );
 275+ }
 276+
 277+ function testEncodeJsVarFloatString() {
 278+ $this->assertEquals(
 279+ '"1.23456"',
 280+ Xml::encodeJsVar( '1.23456' ),
 281+ 'encodeJsVar() with float-like string'
 282+ );
 283+ }
252284 }
Index: trunk/phase3/includes/Xml.php
@@ -583,8 +583,8 @@
584584 $s = $value ? 'true' : 'false';
585585 } elseif ( is_null( $value ) ) {
586586 $s = 'null';
587 - } elseif ( is_int( $value ) ) {
588 - $s = $value;
 587+ } elseif ( is_int( $value ) || is_float( $value ) ) {
 588+ $s = strval($value);
589589 } elseif ( is_array( $value ) && // Make sure it's not associative.
590590 array_keys($value) === range( 0, count($value) - 1 ) ||
591591 count($value) == 0

Follow-up revisions

RevisionCommit summaryAuthorDate
r85151MFT: r82000, r82004, r82020, r82025, r82038, r82039, r82048, r82070, r82081, ...demon20:39, 1 April 2011

Comments

#Comment by Jeroen De Dauw (talk | contribs)   01:11, 14 February 2011

Thanks Brion :)

Status & tagging log