cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r987311 - in /cassandra/trunk: src/java/org/apache/cassandra/utils/FBUtilities.java test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
Date Thu, 19 Aug 2010 21:01:22 GMT
Author: gdusbabek
Date: Thu Aug 19 21:01:22 2010
New Revision: 987311

URL: http://svn.apache.org/viewvc?rev=987311&view=rev
Log:
FBUtilities.hexToBytes doesn't handle odd-length strings. patch by Gary Dusbabek, reviewed
by Jon Hermes. CASSANDRA-1411

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
    cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=987311&r1=987310&r2=987311&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java Thu Aug 19 21:01:22
2010
@@ -304,7 +304,8 @@ public class FBUtilities
 
     public static byte[] hexToBytes(String str)
     {
-        assert str.length() % 2 == 0;
+        if (str.length() % 2 == 1)
+            str = "0" + str;
         byte[] bytes = new byte[str.length()/2];
         for (int i = 0; i < bytes.length; i++)
         {

Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java?rev=987311&r1=987310&r2=987311&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java Thu Aug 19 21:01:22
2010
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEqu
 
 import java.io.IOException;
 import java.nio.charset.CharacterCodingException;
+import java.util.Arrays;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.cassandra.db.IClock;
@@ -44,6 +45,32 @@ public class FBUtilitiesTest 
             assertArrayEquals(b, c);
         }
     }
+    
+    @Test
+    public void testHexToBytesStringConversion()
+    {
+        String[] values = new String[]
+        {
+            "0",
+            "10",
+            "100",
+            "101",
+            "f",
+            "ff"
+        };
+        byte[][] expected = new byte[][]
+        {
+            new byte[] { 0x00 },
+            new byte[] { 0x10 },
+            new byte[] { 0x01, 0x00 },
+            new byte[] { 0x01, 0x01 },
+            new byte[] { 0x0f },
+            new byte[] { (byte)0x000000ff }
+        };
+        
+        for (int i = 0; i < values.length; i++)
+            assert Arrays.equals(FBUtilities.hexToBytes(values[i]), expected[i]);
+    }
 
     @Test
     public void testIntBytesConversions()



Mime
View raw message