From f25d287afae684141edfdcbb43296a7ea6e7e83b Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 24 Jun 2023 20:03:54 +0400 Subject: [PATCH 1/2] Enhanced the test data to demonstrate issue#950 Presence of the "faviconMimeType" attribute in a book entry in library.xml file is enough for libkiwix to assume that the book contains an illustration (even if the "favicon" attribute is missing). --- test/data/library.xml | 2 ++ test/library_server.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/data/library.xml b/test/data/library.xml index 1f569f09e..7a2fcdf9c 100644 --- a/test/data/library.xml +++ b/test/data/library.xml @@ -32,6 +32,7 @@ articleCount="284" mediaCount="2" size="123" + faviconMimeType="image/png;favicon_attribute_is_absent" > diff --git a/test/library_server.cpp b/test/library_server.cpp index 2274ccf4c..251e2928c 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -144,7 +144,9 @@ std::string maskVariableOPDSFeedData(std::string s) "wikipedia_ru_ray_charles",\ "",\ "public_tag_with_a_value:value_of_a_public_tag;_private_tag_with_a_value:value_of_a_private_tag;wikipedia;_pictures:no;_videos:no;_details:no",\ - "",\ + "\n ", \ "zimfile", \ "zimfile", \ "125952"\ From f41007989bb6b04f8eca4aba6665a434eed76661 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 24 Jun 2023 20:10:41 +0400 Subject: [PATCH 2/2] Fool-proof checking of book illustration presence Now (in a library.xml flow) a book is considered to contain an illustration only if both "faviconMimeType" and "favicon" attributes are set to non-empty values. --- src/book.cpp | 9 +++++---- test/library_server.cpp | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/book.cpp b/src/book.cpp index 316645ccf..55d38df48 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -117,11 +117,12 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir) m_articleCount = strtoull(ATTR("articleCount"), 0, 0); m_mediaCount = strtoull(ATTR("mediaCount"), 0, 0); m_size = strtoull(ATTR("size"), 0, 0) << 10; - std::string favicon_mimetype = ATTR("faviconMimeType"); - if (! favicon_mimetype.empty()) { + const std::string faviconMimeType = ATTR("faviconMimeType"); + const std::string faviconBase64EncodedData = ATTR("favicon"); + if ( !faviconMimeType.empty() && !faviconBase64EncodedData.empty() ) { const auto favicon = std::make_shared(); - favicon->data = base64_decode(ATTR("favicon")); - favicon->mimeType = favicon_mimetype; + favicon->data = base64_decode(faviconBase64EncodedData); + favicon->mimeType = faviconMimeType; favicon->url = ATTR("faviconUrl"); m_illustrations.assign(1, favicon); } diff --git a/test/library_server.cpp b/test/library_server.cpp index 251e2928c..2274ccf4c 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -144,9 +144,7 @@ std::string maskVariableOPDSFeedData(std::string s) "wikipedia_ru_ray_charles",\ "",\ "public_tag_with_a_value:value_of_a_public_tag;_private_tag_with_a_value:value_of_a_private_tag;wikipedia;_pictures:no;_videos:no;_details:no",\ - "\n ", \ + "",\ "zimfile", \ "zimfile", \ "125952"\