crowdagger / epub-builder

A Rust library for generating EPUB files
Mozilla Public License 2.0
135 stars 45 forks source link

Zip file uses wrong slashes on Windows #4

Closed mdsherry closed 5 years ago

mdsherry commented 6 years ago

Zip files should always use forward-slashes in paths (see e.g. this bug report for a citation).

In three different places in epub.rs, a path is created using Path::new("OEBPS").join(...), which uses the default path item separator for the platform. On Windows, this is a backslash.

ZipCommand handles this correctly, but ZipLibrary passes the path on verbatim. The resulting EPUB fails validation at http://validator.idpf.org/ because of files mentioned in the manifest that it can't find (e.g. OEBPS/foo.html) and files that it can see but aren't in the manifest (e.g. OEBPS\foo.html).

A simple solution that I've tested locally is changing https://github.com/lise-henry/epub-builder/blob/master/src/zip_library.rs#L59 to

let file = format!("{}", path.as_ref().display()).replace('\\', "/");

which feels like a hack, but works. I suspect a proper fix would involve also fixing up paths added to the manifest, in case a user adds an EpubContent with a \ in it.

crowdagger commented 5 years ago

Sorry to have taken so much time, but it should be fixed (I used your suggestion, but only on Windows; I'll try to think of a better fix later). Thanks!