Browse Source

fixed Std.parseInt(hex)

Nicolas Cannasse 14 years ago
parent
commit
2f78f8233a
3 changed files with 8 additions and 7 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 6 7
      std/flash/_std/Std.hx
  3. 1 0
      tests/unit/TestBasetypes.hx

+ 1 - 0
doc/CHANGES.txt

@@ -15,6 +15,7 @@
 	neko : added spod_macro support
 	neko : allowed serialization of haxe.Int32 (as Int)
 	all : fixed invalid optimization of two constant numbers comparison
+	flash8 : bugfix Std.parseInt with some hex values
 
 2011-01-30: 2.07
 	all : fixed completion support with --remap

+ 6 - 7
std/flash/_std/Std.hx

@@ -39,14 +39,13 @@
 	}
 
 	public static function parseInt( x : String ) : Null<Int> untyped {
-		var v = _global["parseInt"](x, 10);
-		if( _global["isNaN"](v) ) {
-			if( x.charCodeAt(1) == 'x'.code ) {
-				v = _global["parseInt"](x);
-				if( !_global["isNaN"](v) ) return v; // fast isNaN
-			}
+		var v;
+		if( x.charCodeAt(1) == 'x'.code )
+			v = _global["parseInt"](x);
+		else
+			v = _global["parseInt"](x, 10);
+		if( _global["isNaN"](v) )
 			return null;
-		}
 		return v;
 	}
 

+ 1 - 0
tests/unit/TestBasetypes.hx

@@ -107,6 +107,7 @@ class TestBasetypes extends Test {
 		eq( Std.parseInt("a10"), null );
 		eq( Std.parseInt(null), null );
 		eq( Std.parseInt("0xFF"), 255 );
+		eq( Std.parseInt("0x123"), 291 );
 		unspec(function() Std.parseInt("0xFG"));
 
 		eq( Std.parseFloat("0"), 0. );