hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1401127 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/util/Bytes.java test/java/org/apache/hadoop/hbase/util/TestBytes.java
Date Tue, 23 Oct 2012 00:00:55 GMT
Author: enis
Date: Tue Oct 23 00:00:54 2012
New Revision: 1401127

URL: http://svn.apache.org/viewvc?rev=1401127&view=rev
Log:
HBASE-7016 port HBASE-6518 'Bytes.toBytesBinary() incorrect trailing backslash escape' to
0.94

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/Bytes.java?rev=1401127&r1=1401126&r2=1401127&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/Bytes.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/Bytes.java Tue Oct 23 00:00:54
2012
@@ -378,19 +378,12 @@ public class Bytes {
   }
 
   public static byte [] toBytesBinary(String in) {
-    // this may be bigger than we need, but lets be safe.
+    // this may be bigger than we need, but let's be safe.
     byte [] b = new byte[in.length()];
     int size = 0;
     for (int i = 0; i < in.length(); ++i) {
       char ch = in.charAt(i);
-      if (ch == '\\') {
-        // begin hex escape:
-        char next = in.charAt(i+1);
-        if (next != 'x') {
-          // invalid escape sequence, ignore this one.
-          b[size++] = (byte)ch;
-          continue;
-        }
+      if (ch == '\\' && in.length() > i+1 && in.charAt(i+1) == 'x') {
         // ok, take next 2 hex digits.
         char hd1 = in.charAt(i+2);
         char hd2 = in.charAt(i+3);

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java?rev=1401127&r1=1401126&r2=1401127&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java Tue Oct
23 00:00:54 2012
@@ -290,6 +290,13 @@ public class TestBytes extends TestCase 
     assertEquals("", Bytes.readStringFixedSize(dis, 9));
   }
 
+  public void testToBytesBinaryTrailingBackslashes() throws Exception {
+    try {
+      Bytes.toBytesBinary("abc\\x00\\x01\\");
+    } catch (StringIndexOutOfBoundsException ex) {
+      fail("Illegal string access: " + ex.getMessage());
+    }
+  }
 
   @org.junit.Rule
   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =



Mime
View raw message