mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #507 from kiwix/fix_for_issue_504
/catalog/search handles out-of-bounds pagination
This commit is contained in:
commit
b82fff9855
|
@ -692,8 +692,9 @@ InternalServer::search_catalog(const RequestContext& request,
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
opdsDumper.setTitle("Search result for " + query);
|
opdsDumper.setTitle("Search result for " + query);
|
||||||
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
||||||
auto totalResults = bookIdsToDump.size();
|
const auto totalResults = bookIdsToDump.size();
|
||||||
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex);
|
const auto s = std::min(startIndex, totalResults);
|
||||||
|
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+s);
|
||||||
if (count>0 && bookIdsToDump.size() > count) {
|
if (count>0 && bookIdsToDump.size() > count) {
|
||||||
bookIdsToDump.resize(count);
|
bookIdsToDump.resize(count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -846,3 +846,54 @@ TEST_F(LibraryServerTest, catalog_search_by_category)
|
||||||
"</feed>\n"
|
"</feed>\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(LibraryServerTest, catalog_search_results_pagination)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
const auto r = zfs1_->GET("/catalog/search?count=1");
|
||||||
|
EXPECT_EQ(r->status, 200);
|
||||||
|
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||||
|
OPDS_FEED_TAG
|
||||||
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
|
" <title>Search result for <Empty query></title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>3</totalResults>\n"
|
||||||
|
" <startIndex>0</startIndex>\n"
|
||||||
|
" <itemsPerPage>1</itemsPerPage>\n"
|
||||||
|
CATALOG_LINK_TAGS
|
||||||
|
CHARLES_RAY_CATALOG_ENTRY
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto r = zfs1_->GET("/catalog/search?start=1&count=1");
|
||||||
|
EXPECT_EQ(r->status, 200);
|
||||||
|
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||||
|
OPDS_FEED_TAG
|
||||||
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
|
" <title>Search result for <Empty query></title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>3</totalResults>\n"
|
||||||
|
" <startIndex>1</startIndex>\n"
|
||||||
|
" <itemsPerPage>1</itemsPerPage>\n"
|
||||||
|
CATALOG_LINK_TAGS
|
||||||
|
RAY_CHARLES_CATALOG_ENTRY
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto r = zfs1_->GET("/catalog/search?start=100&count=10");
|
||||||
|
EXPECT_EQ(r->status, 200);
|
||||||
|
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||||
|
OPDS_FEED_TAG
|
||||||
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
|
" <title>Search result for <Empty query></title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>3</totalResults>\n"
|
||||||
|
" <startIndex>100</startIndex>\n"
|
||||||
|
" <itemsPerPage>0</itemsPerPage>\n"
|
||||||
|
CATALOG_LINK_TAGS
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue