commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r945189 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/TarUtils.java test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
Date Mon, 17 May 2010 14:51:18 GMT
Author: sebb
Date: Mon May 17 14:51:17 2010
New Revision: 945189

URL: http://svn.apache.org/viewvc?rev=945189&view=rev
Log:
COMPRESS-114 Fix name round-trip problem

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=945189&r1=945188&r2=945189&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
Mon May 17 14:51:17 2010
@@ -95,11 +95,11 @@ public class TarUtils {
         int          end = offset + length;
 
         for (int i = offset; i < end; ++i) {
-            if (buffer[i] == 0) { // Trailing null
+            byte b = buffer[i];
+            if (b == 0) { // Trailing null
                 break;
             }
-
-            result.append((char) buffer[i]);
+            result.append((char) (b & 0xFF)); // Allow for sign-extension
         }
 
         return result.toString();

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java?rev=945189&r1=945188&r2=945189&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
Mon May 17 14:51:17 2010
@@ -116,4 +116,19 @@ public class TarUtilsTest extends TestCa
         } catch (IllegalArgumentException expected) {
         }
     }
+    
+    public void testRoundTripNames(){
+        checkName("");
+        checkName("The quick brown fox\n");
+        checkName("\177");
+        // checkName("\0"); // does not work, because NUL is ignored
+        // COMPRESS-114
+        checkName("0302-0601-3±±±F06±W220±ZB±LALALA±±±±±±±±±±CAN±±DC±±±04±060302±MOE.model");
+    }
+
+    private void checkName(String string) {
+        byte buff[] = new byte[100];
+        int len = TarUtils.formatNameBytes(string, buff, 0, buff.length);
+        assertEquals(string, TarUtils.parseName(buff, 0, len));
+    }
 }



Mime
View raw message