Index: trunk/phase3/tests/phpunit/includes/XmlTest.php |
— | — | @@ -248,4 +248,36 @@ |
249 | 249 | 'encodeJsVar() with object' |
250 | 250 | ); |
251 | 251 | } |
| 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 | + } |
252 | 284 | } |
Index: trunk/phase3/includes/Xml.php |
— | — | @@ -583,8 +583,8 @@ |
584 | 584 | $s = $value ? 'true' : 'false'; |
585 | 585 | } elseif ( is_null( $value ) ) { |
586 | 586 | $s = 'null'; |
587 | | - } elseif ( is_int( $value ) ) { |
588 | | - $s = $value; |
| 587 | + } elseif ( is_int( $value ) || is_float( $value ) ) { |
| 588 | + $s = strval($value); |
589 | 589 | } elseif ( is_array( $value ) && // Make sure it's not associative. |
590 | 590 | array_keys($value) === range( 0, count($value) - 1 ) || |
591 | 591 | count($value) == 0 |