You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2019/08/20 18:59:10 UTC

[commons-compress] branch master updated: COMPRESS-478 only use the last part of the archive's path

This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new f1255d9  COMPRESS-478 only use the last part of the archive's path
f1255d9 is described below

commit f1255d9dec0cbb06301998bb1af46a8f23958074
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Tue Aug 20 19:01:39 2019 +0200

    COMPRESS-478 only use the last part of the archive's path
---
 pom.xml                                                      | 12 ------------
 .../apache/commons/compress/archivers/sevenz/SevenZFile.java |  7 ++++---
 .../commons/compress/archivers/sevenz/SevenZFileTest.java    |  3 +--
 3 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7b839ff..cecbedf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,18 +91,6 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-library</artifactId>
-      <version>1.3</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-core</artifactId>
-      <version>1.3</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>com.github.luben</groupId>
       <artifactId>zstd-jni</artifactId>
       <version>1.4.0-1</version>
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index adcc023..00d2fde 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -1402,11 +1402,12 @@ public class SevenZFile implements Closeable {
             return null;
         }
 
-        final int dotPos = fileName.lastIndexOf(".");
+        final String lastSegment = new File(fileName).getName();
+        final int dotPos = lastSegment.lastIndexOf(".");
         if (dotPos > 0) { // if the file starts with a dot then this is not an extension
-            return fileName.substring(0, dotPos);
+            return lastSegment.substring(0, dotPos);
         }
-        return fileName + "~";
+        return lastSegment + "~";
     }
 
     private static final CharsetEncoder PASSWORD_ENCODER = StandardCharsets.UTF_16LE.newEncoder();
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index 008aeba..0982259 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -18,7 +18,6 @@
 package org.apache.commons.compress.archivers.sevenz;
 
 import static org.junit.Assert.*;
-import static org.hamcrest.Matchers.endsWith;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -316,7 +315,7 @@ public class SevenZFileTest extends AbstractTestCase {
     @Test
     public void getDefaultNameWorksAsExpected() throws Exception {
         try (SevenZFile sevenZFile = new SevenZFile(getFile("bla.deflate64.7z"))) {
-            assertThat(sevenZFile.getDefaultName(), endsWith("bla.deflate64"));
+            assertEquals("bla.deflate64", sevenZFile.getDefaultName());
         }
         try (SevenZFile sevenZFile = new SevenZFile(Files.newByteChannel(getFile("bla.deflate64.7z").toPath()))) {
             assertNull(sevenZFile.getDefaultName());