fix(fb2): use base64 decoder aware of newlines (#2229)
This commit is contained in:
+2
-2
@@ -51,7 +51,7 @@ public class Fb2MetadataExtractor implements FileMetadataExtractor {
|
||||
String contentType = binary.getAttribute("content-type");
|
||||
if (contentType != null && contentType.startsWith("image/")) {
|
||||
String base64Data = binary.getTextContent().trim();
|
||||
return Base64.getDecoder().decode(base64Data);
|
||||
return Base64.getMimeDecoder().decode(base64Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class Fb2MetadataExtractor implements FileMetadataExtractor {
|
||||
Element binary = (Element) binaries.item(i);
|
||||
if (imageId.equals(binary.getAttribute("id"))) {
|
||||
String base64Data = binary.getTextContent().trim();
|
||||
return Base64.getDecoder().decode(base64Data);
|
||||
return Base64.getMimeDecoder().decode(base64Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -498,6 +498,23 @@ class Fb2MetadataExtractorTest {
|
||||
assertThat(cover).isEqualTo(imageData);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractCover_binaryWithNewLines() throws IOException {
|
||||
byte[] imageData = {(byte) 0x89, 0x50, 0x4E, 0x47};
|
||||
File file = writeFb2("""
|
||||
<description><title-info/></description>
|
||||
<binary id="cover.jpg" content-type="image/jpeg">
|
||||
iVB
|
||||
ORw==
|
||||
</binary>
|
||||
"""
|
||||
);
|
||||
|
||||
byte[] cover = extractor.extractCover(file);
|
||||
|
||||
assertThat(cover).isEqualTo(imageData);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractCover_fallbackToCoverpageReference() throws IOException {
|
||||
byte[] imageData = {0x01, 0x02, 0x03, 0x04};
|
||||
|
||||
Reference in New Issue
Block a user