Skip to content

Commit 234606b

Browse files
authored
Merge pull request #686 from kiwix/catalog_search_with_zero_count
2 parents 7440652 + b8328a7 commit 234606b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/server/internalServer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ InternalServer::search_catalog(const RequestContext& request,
720720
const auto totalResults = bookIdsToDump.size();
721721
const size_t count = request.get_optional_param("count", 10UL);
722722
const size_t startIndex = request.get_optional_param("start", 0UL);
723-
bookIdsToDump = subrange(bookIdsToDump, startIndex, count);
723+
const size_t intendedCount = count > 0 ? count : bookIdsToDump.size();
724+
bookIdsToDump = subrange(bookIdsToDump, startIndex, intendedCount);
724725
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
725726
return bookIdsToDump;
726727
}

test/server.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,24 @@ TEST_F(LibraryServerTest, catalog_search_by_category)
929929

930930
TEST_F(LibraryServerTest, catalog_search_results_pagination)
931931
{
932+
{
933+
const auto r = zfs1_->GET("/ROOT/catalog/search?count=0");
934+
EXPECT_EQ(r->status, 200);
935+
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
936+
OPDS_FEED_TAG
937+
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
938+
" <title>Filtered zims (count=0)</title>\n"
939+
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
940+
" <totalResults>3</totalResults>\n"
941+
" <startIndex>0</startIndex>\n"
942+
" <itemsPerPage>3</itemsPerPage>\n"
943+
CATALOG_LINK_TAGS
944+
CHARLES_RAY_CATALOG_ENTRY
945+
RAY_CHARLES_CATALOG_ENTRY
946+
UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY
947+
"</feed>\n"
948+
);
949+
}
932950
{
933951
const auto r = zfs1_->GET("/ROOT/catalog/search?count=1");
934952
EXPECT_EQ(r->status, 200);

0 commit comments

Comments
 (0)