Skip to content

Ensure that if entryName contains / char they are replaced by "File.separator" #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
"" )
+ suffix;
boolean fileOnDiskIsNewerThanEntry = targetFileName.lastModified() >= entryDate.getTime();
boolean differentCasing = !entryName.equals( relativeCanonicalDestPath );
boolean differentCasing = !entryName.replace("/", File.separator).equals( relativeCanonicalDestPath );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is wrong. Both strings would need to have "/" be replaced by File.separator if you want to look for different casing.


String casingMessage = String.format( "Archive entry '%s' and existing file '%s' names differ only by case."
+ " This may lead to an unexpected outcome on case-insensitive filesystems.", entryName, canonicalDestPath );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ public void shouldNotWarnAboutDifferentCasingForDirectoryEntries() throws IOExce
assertThat( this.log.getWarns(), not( hasItem( new LogMessageMatcher( "names differ only by case" ) ) ) );
}


@Test
public void shouldExtractWhenCasingDifferOnlyInEntryNamePath() throws IOException
{
// given
File file = new File( temporaryFolder.getRoot() + File.separator + "directory", "whatever.txt" ); // does not create the file!
file.mkdirs();
file.createNewFile();
String entryname = "directory/whatever.txt";
Date entryDate = new Date(System.currentTimeMillis()+5000);

// when & then
this.abstractUnArchiver.setOverwrite( true );
assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is ( true ) );
}

static class LogMessageMatcher extends BaseMatcher<CapturingLog.Message> {
private final StringContains delegateMatcher;

Expand Down