Skip to content

Commit

Permalink
Use case sensitive comparison for file headers (#396)
Browse files Browse the repository at this point in the history
* Use case sensitive comparison for file headers

Allow creating zip archives that contain multiple files that differ only by case sensitivity.

* Add case sensitivity test
  • Loading branch information
enoyhs authored Jun 21, 2022
1 parent f288029 commit 723a716
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/net/lingala/zip4j/headers/HeaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static FileHeader getFileHeaderWithExactMatch(ZipModel zipModel, String
continue;
}

if (fileName.equalsIgnoreCase(fileNameForHdr)) {
if (fileName.equals(fileNameForHdr)) {
return fileHeader;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/net/lingala/zip4j/headers/HeaderUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ public void testGetFileHeaderWithExactMatch() throws ZipException {
assertThat(fileHeader.getFileName()).isEqualTo(FILE_NAME);
}

@Test
public void testGetFileHeaderWithExactMatchCaseSensitive() throws ZipException {
final String lowerCaseFile = FILE_NAME.toLowerCase();
final String upperCaseFile = FILE_NAME.toUpperCase();
ZipModel zipModel = new ZipModel();
CentralDirectory centralDirectory = new CentralDirectory();
centralDirectory.setFileHeaders(Arrays.asList(
generateFileHeader(lowerCaseFile),
generateFileHeader(upperCaseFile)
));
zipModel.setCentralDirectory(centralDirectory);

assertThat(centralDirectory.getFileHeaders()).hasSize(2);

FileHeader fileHeaderLower = HeaderUtil.getFileHeader(zipModel, lowerCaseFile);
assertThat(fileHeaderLower).isNotNull();
assertThat(fileHeaderLower.getFileName()).isEqualTo(lowerCaseFile);

FileHeader fileHeaderUpper = HeaderUtil.getFileHeader(zipModel, upperCaseFile);
assertThat(fileHeaderUpper).isNotNull();
assertThat(fileHeaderUpper.getFileName()).isEqualTo(upperCaseFile);
}

@Test
public void testGetFileHeaderWithWindowsFileSeparator() throws ZipException {
ZipModel zipModel = new ZipModel();
Expand Down

0 comments on commit 723a716

Please sign in to comment.