Ver código fonte

[php] fix haxe.io.Bytes.ofString() (fixes #8212)

Alexander Kuzmenko 6 anos atrás
pai
commit
387a72d621

+ 5 - 3
std/php/_std/haxe/io/Bytes.hx

@@ -21,6 +21,8 @@
  */
  */
 package haxe.io;
 package haxe.io;
 
 
+import php.Global;
+
 class Bytes {
 class Bytes {
 
 
 	public var length(default,null) : Int;
 	public var length(default,null) : Int;
@@ -185,12 +187,12 @@ class Bytes {
 	public static inline function ofData( b : BytesData ) : Bytes {
 	public static inline function ofData( b : BytesData ) : Bytes {
 		return new Bytes(b.length, b);
 		return new Bytes(b.length, b);
 	}
 	}
-	
+
 	public static function ofHex( s : String ) : Bytes {
 	public static function ofHex( s : String ) : Bytes {
-		var len = s.length;
+		var len = Global.strlen(s);
 		if ( (len & 1) != 0 ) throw "Not a hex string (odd number of digits)";
 		if ( (len & 1) != 0 ) throw "Not a hex string (odd number of digits)";
 		var b : String = php.Global.hex2bin(s);
 		var b : String = php.Global.hex2bin(s);
-		return new Bytes(b.length, b);
+		return new Bytes(Global.strlen(b), b);
 	}
 	}
 
 
 	/**
 	/**

+ 12 - 0
tests/unit/src/unit/issues/Issue8212.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+import haxe.io.Bytes;
+
+class Issue8212 extends unit.Test {
+	function test() {
+		var hex = "010A7F0AC2800ADFBF0AE0A0800AED9FBF0AEE80800AEFBFBD0AF09F9882F09F9884F09F98990AC8A70A";
+		var bytes = Bytes.ofHex(hex);
+		eq(hex.length, bytes.length);
+		eq(hex, bytes.toHex());
+	}
+}