diff --git a/railo-java/railo-core/src/railo/runtime/coder/HexCoder.java b/railo-java/railo-core/src/railo/runtime/coder/HexCoder.java index d947abca64..3944029bfe 100644 --- a/railo-java/railo-core/src/railo/runtime/coder/HexCoder.java +++ b/railo-java/railo-core/src/railo/runtime/coder/HexCoder.java @@ -1,5 +1,7 @@ package railo.runtime.coder; +import org.apache.commons.codec.binary.Hex; + import railo.commons.io.CharsetUtil; @@ -14,19 +16,7 @@ public final class HexCoder { * @return encoed String */ public static String encode(byte[] bytes) { - String retorno = ""; - if (bytes==null || bytes.length==0) { - return retorno; - } - for (int i=0; i> 4; - d2 += (d2 < 10) ? 48 : 55; - retorno = retorno + (char)d2 + (char)d1; - } - return retorno; + return Hex.encodeHexString(bytes).toUpperCase(); } /** diff --git a/tests/testcases/functions/BinaryEncode.cfc b/tests/testcases/functions/BinaryEncode.cfc new file mode 100644 index 0000000000..cc88ed41a4 --- /dev/null +++ b/tests/testcases/functions/BinaryEncode.cfc @@ -0,0 +1,13 @@ +component extends="org.railo.cfml.test.RailoTestCase" { + + public function setUp() { + variables.emptyBinary = CharsetDecode("", "utf-8"); + variables.binaryHello = CharsetDecode("Hello", "utf-8"); + } + + function testHex() { + $assert.isEqualWithCase("", BinaryEncode(variables.emptyBinary, "hex")); + $assert.isEqualWithCase("48656C6C6F", BinaryEncode(variables.binaryHello, "hex")); + } + +}