commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/2] commons-compress git commit: empty values mean "remove the mapping" in PAX headers
Date Wed, 23 Mar 2016 19:56:13 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master bf20428c5 -> c37115b71


empty values mean "remove the mapping" in PAX headers


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/96e45314
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/96e45314
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/96e45314

Branch: refs/heads/master
Commit: 96e453145171c4a2a34d749c8d0a15bde5a6f21c
Parents: bf20428
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Wed Mar 23 20:36:00 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Mar 23 20:36:00 2016 +0100

----------------------------------------------------------------------
 .../archivers/tar/TarArchiveInputStream.java    | 28 +++++++++++---------
 .../tar/TarArchiveInputStreamTest.java          | 22 +++++++++++++++
 2 files changed, 38 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/96e45314/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index becb9a4..410c8ef 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -455,19 +455,23 @@ public class TarArchiveInputStream extends ArchiveInputStream {
                             String keyword = coll.toString(CharsetNames.UTF_8);
                             // Get rest of entry
                             final int restLen = len - read;
-                            byte[] rest = new byte[restLen];
-                            int got = IOUtils.readFully(i, rest);
-                            if (got != restLen) {
-                                throw new IOException("Failed to read "
-                                                      + "Paxheader. Expected "
-                                                      + restLen
-                                                      + " bytes, read "
-                                                      + got);
+                            if (restLen == 1) { // only NL
+                                headers.remove(keyword);
+                            } else {
+                                byte[] rest = new byte[restLen];
+                                int got = IOUtils.readFully(i, rest);
+                                if (got != restLen) {
+                                    throw new IOException("Failed to read "
+                                                          + "Paxheader. Expected "
+                                                          + restLen
+                                                          + " bytes, read "
+                                                          + got);
+                                }
+                                // Drop trailing NL
+                                String value = new String(rest, 0,
+                                                          restLen - 1, CharsetNames.UTF_8);
+                                headers.put(keyword, value);
                             }
-                            // Drop trailing NL
-                            String value = new String(rest, 0,
-                                                      restLen - 1, CharsetNames.UTF_8);
-                            headers.put(keyword, value);
                             break;
                         }
                         coll.write((byte) ch);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/96e45314/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 862e02b..b1519a2 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -58,6 +58,28 @@ public class TarArchiveInputStreamTest {
     }
 
     @Test
+    public void secondEntryWinsWhenPaxHeaderContainsDuplicateKey() throws Exception {
+        final InputStream is = new ByteArrayInputStream(new byte[1]);
+        final TarArchiveInputStream tais = new TarArchiveInputStream(is);
+        Map<String, String> headers = tais
+            .parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n11 foo=baz\n"
+                                                      .getBytes(CharsetNames.UTF_8)));
+        assertEquals(1, headers.size());
+        assertEquals("baz", headers.get("foo"));
+        tais.close();
+    }
+
+    @Test
+    public void paxHeaderEntryWithEmptyValueRemovesKey() throws Exception {
+        final InputStream is = new ByteArrayInputStream(new byte[1]);
+        final TarArchiveInputStream tais = new TarArchiveInputStream(is);
+        Map<String, String> headers = tais
+            .parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n7 foo=\n"
+                                                      .getBytes(CharsetNames.UTF_8)));
+        assertEquals(0, headers.size());
+    }
+
+    @Test
     public void readPaxHeaderWithEmbeddedNewline() throws Exception {
         final InputStream is = new ByteArrayInputStream(new byte[1]);
         final TarArchiveInputStream tais = new TarArchiveInputStream(is);


Mime
View raw message