From 4f6a5759aacd14568f3026d6f5041355c37b2d35 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 18 Apr 2023 14:24:00 +0400 Subject: [PATCH 1/3] LibraryServerTest.catalog_v2_entries_multiple_filters --- test/library_server.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/library_server.cpp b/test/library_server.cpp index a472f2356..844fcdd62 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -793,6 +793,24 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_language) } } +TEST_F(LibraryServerTest, catalog_v2_entries_multiple_filters) +{ + { + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?lang=fra&category=jazz"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + CATALOG_V2_ENTRIES_PREAMBLE("?lang=fra&category=jazz") + " Filtered Entries (lang=fra&category=jazz)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 1\n" + " 0\n" + " 1\n" + CHARLES_RAY_CATALOG_ENTRY + "\n" + ); + } +} + TEST_F(LibraryServerTest, catalog_v2_individual_entry_access) { const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entry/raycharles"); @@ -1193,7 +1211,7 @@ TEST_F(LibraryServerTest, noJS) { FILTERS_HTML("") HOME_BODY_0_RESULTS FINAL_HTML_TEXT); - + // no_js_download r = zfs1_->GET("/ROOT%23%3F/nojs/download/zimfile"); EXPECT_EQ(r->status, 200); From ebe16f92a52fc0358d52301bb54d4dfbdf57e77c Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 18 Apr 2023 14:33:40 +0400 Subject: [PATCH 2/3] Fixed OPDS XML output for multiple filters In XML any & symbols acting as parameter separators in URL search components must be HTML-escaped. --- static/templates/catalog_v2_entries.xml | 2 +- test/library_server.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/static/templates/catalog_v2_entries.xml b/static/templates/catalog_v2_entries.xml index 223aae9c3..c0eb9dcc9 100644 --- a/static/templates/catalog_v2_entries.xml +++ b/static/templates/catalog_v2_entries.xml @@ -6,7 +6,7 @@ {{feed_id}} GET("/ROOT%23%3F/catalog/v2/entries?start=1&count=1"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), - CATALOG_V2_ENTRIES_PREAMBLE("?start=1&count=1") + CATALOG_V2_ENTRIES_PREAMBLE("?start=1&count=1") " Filtered Entries (start=1&count=1)\n" " YYYY-MM-DDThh:mm:ssZ\n" " 3\n" @@ -799,7 +799,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_multiple_filters) const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?lang=fra&category=jazz"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), - CATALOG_V2_ENTRIES_PREAMBLE("?lang=fra&category=jazz") + CATALOG_V2_ENTRIES_PREAMBLE("?lang=fra&category=jazz") " Filtered Entries (lang=fra&category=jazz)\n" " YYYY-MM-DDThh:mm:ssZ\n" " 1\n" From 6f0e55d60339c1ae5b62cc2bac24d91d25960780 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 18 Apr 2023 14:45:07 +0400 Subject: [PATCH 3/3] A slight simplification of the mustache template Got rid of the partial vs full entries logic in the mustache template - now it is entirely contained in `OPDSDumper::dumpOPDSFeedV2()`. --- src/opds_dumper.cpp | 6 +++--- static/templates/catalog_v2_entries.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index a8b1be9ed..bdb21be7c 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -150,17 +150,17 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector& bookIds, const const auto booksData = getBooksData(library, nameMapper, bookIds, rootLocation, partial); const char* const endpoint = partial ? "/partial_entries" : "/entries"; + const std::string url = endpoint + (query.empty() ? "" : "?" + query); const kainjow::mustache::object template_data{ {"date", gen_date_str()}, {"endpoint_root", endpointRoot}, {"feed_id", gen_uuid(libraryId + endpoint + "?" + query)}, {"filter", onlyAsNonEmptyMustacheValue(query)}, - {"query", query.empty() ? "" : "?" + query}, + {"self_url", url}, {"totalResults", to_string(m_totalResults)}, {"startIndex", to_string(m_startIndex)}, {"itemsPerPage", to_string(m_count)}, - {"books", booksData }, - {"dump_partial_entries", MustacheData(partial)} + {"books", booksData } }; return render_template(RESOURCE::templates::catalog_v2_entries_xml, template_data); diff --git a/static/templates/catalog_v2_entries.xml b/static/templates/catalog_v2_entries.xml index c0eb9dcc9..264c728d9 100644 --- a/static/templates/catalog_v2_entries.xml +++ b/static/templates/catalog_v2_entries.xml @@ -6,7 +6,7 @@ {{feed_id}}