diff --git a/src/main/java/net/lingala/zip4j/tasks/AbstractExtractFileTask.java b/src/main/java/net/lingala/zip4j/tasks/AbstractExtractFileTask.java index 9815c886..dd6113e6 100644 --- a/src/main/java/net/lingala/zip4j/tasks/AbstractExtractFileTask.java +++ b/src/main/java/net/lingala/zip4j/tasks/AbstractExtractFileTask.java @@ -18,7 +18,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.regex.Matcher; import static net.lingala.zip4j.util.InternalZipConstants.FILE_SEPARATOR; @@ -159,21 +158,13 @@ private void checkOutputDirectoryStructure(File outputFile) throws ZipException } private File determineOutputFile(FileHeader fileHeader, String outputPath, String newFileName) { - String outputFileName; + String outputFileName = fileHeader.getFileName(); if (Zip4jUtil.isStringNotNullAndNotEmpty(newFileName)) { outputFileName = newFileName; - } else { - // replace all slashes with file separator - outputFileName = fileHeader.getFileName(); } - return new File(outputPath + FILE_SEPARATOR + outputFileName); } - private String getFileNameWithSystemFileSeparators(String fileNameToReplace) { - return fileNameToReplace.replaceAll("[/\\\\]", Matcher.quoteReplacement(FILE_SEPARATOR)); - } - @Override protected ProgressMonitor.Task getTask() { return ProgressMonitor.Task.EXTRACT_ENTRY; diff --git a/src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java b/src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java index b983c1b4..9b1c41ba 100644 --- a/src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java +++ b/src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java @@ -116,22 +116,6 @@ public void testReadAllWithoutFileHeaderSignatureThrowsException() throws IOExce } } - @Test - public void testReadAllWithFileNameContainsWindowsDriveExcludesIt() throws IOException { - String fileName = "C:\\test.txt"; - ZipModel actualZipModel = generateZipModel(1); - actualZipModel.getCentralDirectory().getFileHeaders().get(0).setFileName(fileName); - File headersFile = writeZipHeaders(actualZipModel); - actualZipModel.setZipFile(headersFile); - - try(RandomAccessFile randomAccessFile = new RandomAccessFile(actualZipModel.getZipFile(), - RandomAccessFileMode.READ.getValue())) { - ZipModel readZipModel = headerReader.readAllHeaders(randomAccessFile, buildDefaultConfig()); - FileHeader fileHeader = readZipModel.getCentralDirectory().getFileHeaders().get(0); - assertThat(fileHeader.getFileName()).isEqualTo("test.txt"); - } - } - @Test public void testReadAllWithoutFileNameWritesNull() throws IOException { ZipModel actualZipModel = generateZipModel(1); @@ -438,4 +422,4 @@ private File writeZipHeaders(ZipModel zipModel) throws IOException { return headersFile; } } -} \ No newline at end of file +}