From bc54e5e335892679e4b7989497b7591cc7623a9e Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 16 Nov 2018 00:11:03 +0300 Subject: [PATCH] Fix full_split behavior on empty string. GitOrigin-RevId: 74fcaeee970ab26f1bee221babf9b6029237c6cc --- td/telegram/InlineQueriesManager.cpp | 6 ------ tdutils/td/utils/misc.h | 3 +++ tdutils/test/misc.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index f48381490..ec5c3c899 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1614,12 +1614,6 @@ bool InlineQueriesManager::load_recently_used_bots(Promise &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()) { diff --git a/tdutils/td/utils/misc.h b/tdutils/td/utils/misc.h index 7998bfc0c..d4a0013c9 100644 --- a/tdutils/td/utils/misc.h +++ b/tdutils/td/utils/misc.h @@ -34,6 +34,9 @@ std::pair split(T s, char delimiter = ' ') { template vector full_split(T s, char delimiter = ' ') { vector result; + if (s.empty()) { + return result; + } while (true) { auto delimiter_pos = s.find(delimiter); if (delimiter_pos == string::npos) { diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index 8ebcde2c6..2bd65b7bc 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -544,7 +544,7 @@ static void test_full_split(Slice str, vector expected) { } TEST(Misc, full_split) { - test_full_split("", {""}); + test_full_split("", {}); test_full_split(" ", {"", ""}); test_full_split(" ", {"", "", ""}); test_full_split("abcdef", {"abcdef"});