Ignore invalid strings in the database.

GitOrigin-RevId: 46d75ea61a1ab03d2f9540f001652ff7c08cd44c
This commit is contained in:
levlam 2018-09-07 19:12:48 +03:00
parent cd33ec58be
commit 2b34a6befa
2 changed files with 15 additions and 14 deletions

View File

@ -414,25 +414,26 @@ bool LanguagePackManager::language_has_strings(Language *language, const vector<
return true;
}
void LanguagePackManager::load_language_string_unsafe(Language *language, const string &key, string &value) {
void LanguagePackManager::load_language_string_unsafe(Language *language, const string &key, const string &value) {
CHECK(is_valid_key(key));
if (value.empty() || value == "3") {
if (!language->is_full_) {
language->deleted_strings_.insert(key);
}
return;
}
if (value[0] == '1') {
language->ordinary_strings_.emplace(key, value.substr(1));
return;
}
CHECK(value[0] == '2');
auto all = full_split(Slice(value).substr(1), '\x00');
CHECK(all.size() == 6);
language->pluralized_strings_.emplace(
key, PluralizedString{all[0].str(), all[1].str(), all[2].str(), all[3].str(), all[4].str(), all[5].str()});
if (value[0] == '2') {
auto all = full_split(Slice(value).substr(1), '\x00');
if (all.size() == 6) {
language->pluralized_strings_.emplace(
key, PluralizedString{all[0].str(), all[1].str(), all[2].str(), all[3].str(), all[4].str(), all[5].str()});
return;
}
}
LOG_IF(ERROR, !value.empty() && value != "3") << "Have invalid value \"" << value << '"';
if (!language->is_full_) {
language->deleted_strings_.insert(key);
}
}
bool LanguagePackManager::load_language_strings(LanguageDatabase *database, Language *language,

View File

@ -104,7 +104,7 @@ class LanguagePackManager : public NetQueryCallback {
static bool language_has_string_unsafe(const Language *language, const string &key);
static bool language_has_strings(Language *language, const vector<string> &keys);
static void load_language_string_unsafe(Language *language, const string &key, string &value);
static void load_language_string_unsafe(Language *language, const string &key, const string &value);
static bool load_language_strings(LanguageDatabase *database, Language *language, const vector<string> &keys);
static td_api::object_ptr<td_api::LanguagePackStringValue> get_language_pack_string_value_object(const string &value);