Fix full_split behavior on empty string.

GitOrigin-RevId: 74fcaeee970ab26f1bee221babf9b6029237c6cc
This commit is contained in:
levlam 2018-11-16 00:11:03 +03:00
parent 6fc90bb699
commit bc54e5e335
3 changed files with 4 additions and 7 deletions

View File

@ -1614,12 +1614,6 @@ bool InlineQueriesManager::load_recently_used_bots(Promise<Unit> &promise) {
auto bot_ids = full_split(saved_bot_ids, ',');
string saved_bots = G()->td_db()->get_binlog_pmc()->get("recently_used_inline_bot_usernames");
auto bot_usernames = full_split(saved_bots, ',');
if (bot_ids.size() == 1 && bot_ids[0].empty()) {
bot_ids.clear();
}
if (bot_usernames.size() == 1 && bot_usernames[0].empty()) {
bot_usernames.clear();
}
if (bot_ids.empty() && bot_usernames.empty()) {
recently_used_bots_loaded_ = 2;
if (!recently_used_bot_user_ids_.empty()) {

View File

@ -34,6 +34,9 @@ std::pair<T, T> split(T s, char delimiter = ' ') {
template <class T>
vector<T> full_split(T s, char delimiter = ' ') {
vector<T> result;
if (s.empty()) {
return result;
}
while (true) {
auto delimiter_pos = s.find(delimiter);
if (delimiter_pos == string::npos) {

View File

@ -544,7 +544,7 @@ static void test_full_split(Slice str, vector<Slice> expected) {
}
TEST(Misc, full_split) {
test_full_split("", {""});
test_full_split("", {});
test_full_split(" ", {"", ""});
test_full_split(" ", {"", "", ""});
test_full_split("abcdef", {"abcdef"});