mirror of
https://github.com/booklore-app/booklore.git
synced 2026-02-19 07:50:56 +01:00
fix(epub): strip formatting from ISBN values to ensure correct extraction (#2248)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -223,8 +223,9 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
||||
if (!scheme.isEmpty()) {
|
||||
switch (scheme) {
|
||||
case "ISBN" -> {
|
||||
if (value.length() == 13) builderMeta.isbn13(value);
|
||||
else if (value.length() == 10) builderMeta.isbn10(value);
|
||||
String cleanValue = value.replaceAll("[- ]", "");
|
||||
if (cleanValue.length() == 13) builderMeta.isbn13(value);
|
||||
else if (cleanValue.length() == 10) builderMeta.isbn10(value);
|
||||
}
|
||||
case "GOODREADS" -> builderMeta.goodreadsId(value);
|
||||
case "COMICVINE" -> builderMeta.comicvineId(value);
|
||||
@@ -235,8 +236,9 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
||||
}
|
||||
} else {
|
||||
if (text.toLowerCase().startsWith("isbn:")) {
|
||||
if (value.length() == 13) builderMeta.isbn13(value);
|
||||
else if (value.length() == 10) builderMeta.isbn10(value);
|
||||
String cleanValue = value.replaceAll("[- ]", "");
|
||||
if (cleanValue.length() == 13) builderMeta.isbn13(value);
|
||||
else if (cleanValue.length() == 10) builderMeta.isbn10(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +386,19 @@ class EpubMetadataExtractorTest {
|
||||
() -> assertEquals("1234567890", result.getIsbn10())
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should extract formatted ISBN-10 as ISBN-10, not ISBN-13")
|
||||
void extractMetadata_withFormattedIsbn10_returnsIsbn10() throws IOException {
|
||||
// "90-206-1280-8" is 13 characters long, causing it to be mistaken for ISBN-13 if formatting isn't stripped
|
||||
File epubFile = createEpubWithIsbn(null, "90-206-1280-8");
|
||||
|
||||
BookMetadata result = extractor.extractMetadata(epubFile);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals("90-206-1280-8", result.getIsbn10());
|
||||
assertNull(result.getIsbn13(), "Should not set ISBN-13 for a formatted ISBN-10");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user