Skip to content
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

Backslashes in zip entry name #262

Closed
dionys opened this issue Sep 19, 2018 · 4 comments
Closed

Backslashes in zip entry name #262

dionys opened this issue Sep 19, 2018 · 4 comments
Labels

Comments

@dionys
Copy link

dionys commented Sep 19, 2018

Some Windows tools creates the zip-archives with the backslashes in the entry names as path separators instead of slashes. E.g.:

foo\bar.txt
foo\baz\qux.bin

The *nix tools accepts this format (with warnings like warning: foo.zip appears to use backslashes as path separators for unzip) and successfully extracts the directory tree. E.g.:

tmp
`- foo
   |- bar.txt
   `- baz
      `- qux.bin

But better-files can't do this. It extracts paths as is, plain not tree:

tmp
|- foo\bar.txt
`- foo\baz\qux.bin

Simple replace in ZipEntryOps.extractTo() method might resolve this problem:

- entry.getName
+ entry.getName.replace("\\", "/")
@dionys dionys changed the title Backslashes in zip entity name Backslashes in zip entry name Sep 19, 2018
@pathikrit pathikrit added the bug label Sep 19, 2018
@pathikrit
Copy link
Owner

I have no way to unit test this - do you have such a zip file you can attach to this issue?

@dionys
Copy link
Author

dionys commented Nov 6, 2018

PowerShell for example:

Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory("C:\Temp\foo", "C:\Temp\foo.zip")

foo.zip

@pathikrit
Copy link
Owner

Reopening this so I can test it. Thanks for the test-case

@pathikrit pathikrit reopened this Nov 7, 2018
@som-snytt
Copy link

I just had a test in scala/scala fail on windows -- it creates a jar with a plugin to load. The reason for the failure was backslashes in entry names due to Path.toString:

val rel: Path = ???   // relative path
jout.putNextEntry(new JarEntry(rel.toString.replace("\\", "/"))) // fix evil windows backslash

It occurred to me to wonder if better-files would help with the backslash curse. Registering my interest here; I haven't gone through the API yet.

As of 2020, I refuse to convert slashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants