Bug fix: Merging language sets to create 'translate_blocked_languages' may be evaded

Because of the 'return' sentence in the previous migrating, the merging process may have been evaded.

BUG=253794
TEST=unit_tests

Review URL: https://chromiumcodereview.appspot.com/18114010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209331 0039d316-1c4b-4281-b951-d872f2087c98
parent 6704f1f8
...@@ -324,22 +324,23 @@ void TranslatePrefs::MigrateUserPrefs(PrefService* user_prefs) { ...@@ -324,22 +324,23 @@ void TranslatePrefs::MigrateUserPrefs(PrefService* user_prefs) {
// keep auto-translated. // keep auto-translated.
DictionaryPrefUpdate update(user_prefs, kPrefTranslateWhitelists); DictionaryPrefUpdate update(user_prefs, kPrefTranslateWhitelists);
DictionaryValue* dict = update.Get(); DictionaryValue* dict = update.Get();
if (!dict || dict->empty()) if (dict && !dict->empty()) {
return; DictionaryValue::Iterator iter(*dict);
DictionaryValue::Iterator iter(*dict); while (!iter.IsAtEnd()) {
while (!iter.IsAtEnd()) { const ListValue* list = NULL;
const ListValue* list = NULL; if (!iter.value().GetAsList(&list) || !list)
if (!iter.value().GetAsList(&list) || !list) break; // Dictionary has either been migrated or new format.
break; // Dictionary has either been migrated or new format. std::string key = iter.key();
std::string key = iter.key(); // Advance the iterator before removing the current element.
// Advance the iterator before removing the current element. iter.Advance();
iter.Advance(); std::string target_lang;
std::string target_lang; if (list->empty() ||
if (list->empty() || !list->GetString(list->GetSize() - 1, &target_lang) || !list->GetString(list->GetSize() - 1, &target_lang) ||
target_lang.empty()) { target_lang.empty()) {
dict->Remove(key, NULL); dict->Remove(key, NULL);
} else { } else {
dict->SetString(key, target_lang); dict->SetString(key, target_lang);
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment