fix(epub): handle literal + when decoding URLs (#2618)

This commit is contained in:
James Ward
2026-09-13 11:26:34 -04:00
committed by GitHub
parent 0b887ae543
commit ce18ce3e22
2 changed files with 68 additions and 0 deletions
@@ -494,6 +494,12 @@ public class EpubMetadataWriter implements MetadataWriter {
private Path getManifestItemPath(Path tempDir, Path opfDir, Element element) throws IOException {
String href = element.getAttribute("href");
// Technically, epub specification only refers to `href` as supporting percent-encoding.
// Unfortunately, the Java URLDecoder.decode method will also do `+` -> space decoding.
// To work around this, we can replace `+` with the percent-encoded version of a plus.
href = href.replaceAll("\\+", "%2b");
String decodedHref = URLDecoder.decode(href, StandardCharsets.UTF_8);
if (decodedHref == null || decodedHref.isBlank()) {
throw new IOException("Manifest item has no href attribute");