campaignd: Explicitly check for before= and after= in add-ons list requests

A regression introduced in e2a64541002f0b4ee885f699c4f0901e441f938a
causes the timestamp-based list filtering to be forcibly enabled in ALL
cases because the author missed that the old code would bail out due to
lexical_cast() throwing an exception if the provided input was empty,
such as when before/after aren't provided in the list request. As a
result, the add-ons list would come up empty for clients because nothing
was matching the resulting time criteria.

The old pattern was a bit oblique to say the least, so I decided it'd be
best to replace it with an explicit check for the attributes' existence
and contents.
This commit is contained in:
Iris Morelle 2019-01-16 20:32:14 -03:00
parent d1ed0dccd1
commit 318a6242ee

View File

@ -586,17 +586,17 @@ void server::handle_request_campaign_list(const server::request& req)
bool before_flag = false;
std::time_t before = epoch;
try {
if(!req.cfg["before"].empty()) {
before += req.cfg["before"].to_time_t();
before_flag = true;
} catch(const bad_lexical_cast&) {}
}
bool after_flag = false;
std::time_t after = epoch;
try {
if(!req.cfg["after"].empty()) {
after += req.cfg["after"].to_time_t();
after_flag = true;
} catch(const bad_lexical_cast&) {}
}
const std::string& name = req.cfg["name"];
const std::string& lang = req.cfg["language"];