Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: components/autofill/core/browser/autofill_profile.cc

Issue 2013063002: Remove diacritics when normalizing autofill profile strings for comparison. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expand unit-tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_profile.cc
diff --git a/components/autofill/core/browser/autofill_profile.cc b/components/autofill/core/browser/autofill_profile.cc
index 0f69602a9265b7a33035cbcbb7552847a1b150ad..fe62770b51c5f28e0b354ae71a60aba30b0d2a47 100644
--- a/components/autofill/core/browser/autofill_profile.cc
+++ b/components/autofill/core/browser/autofill_profile.cc
@@ -36,6 +36,8 @@
#include "components/autofill/core/common/form_field_data.h"
#include "grit/components_strings.h"
#include "third_party/icu/source/common/unicode/uchar.h"
+#include "third_party/icu/source/common/unicode/utypes.h"
+#include "third_party/icu/source/i18n/unicode/translit.h"
#include "third_party/libaddressinput/chromium/addressinput_util.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
@@ -235,6 +237,26 @@ class FindByPhone {
std::string app_locale_;
};
+base::string16 NormalizeForComparison(const base::string16& text) {
+ using icu::UnicodeString;
+ using icu::Transliterator;
+
+ // Remove diacritics and fold case.
Mathieu 2016/05/27 17:47:13 extra space before comment
Roger McFarlane (Chromium) 2016/05/27 20:20:42 Done.
+ UErrorCode status = U_ZERO_ERROR;
+ std::unique_ptr<Transliterator> transliterator(Transliterator::createInstance(
+ "NFD; [:Nonspacing Mark:] Remove; Lower; NFC", UTRANS_FORWARD, status));
Mathieu 2016/05/27 17:47:13 Can we put an explanation (or a link to the explan
Roger McFarlane (Chromium) 2016/05/27 20:20:43 Done.
+ if (U_FAILURE(status)) {
+ // This should not happen. Log the error and fall back.
+ LOG(ERROR) << "normalization failed: " << u_errorName(status);
Mathieu 2016/05/27 17:47:13 Let's capitalize the comment and make it more expl
Roger McFarlane (Chromium) 2016/05/27 20:20:43 Done.
+ return text;
+ }
+
+ UnicodeString value = UnicodeString(text.data(), text.length());
+ transliterator->transliterate(value);
Mathieu 2016/05/27 17:47:13 can we check "if (transliterator)" here? ICU has a
Roger McFarlane (Chromium) 2016/05/27 20:20:43 Done.
+
+ return base::string16(value.getBuffer(), value.length());
+}
+
} // namespace
AutofillProfile::AutofillProfile(const std::string& guid,
@@ -846,7 +868,7 @@ base::string16 AutofillProfile::CanonicalizeProfileString(
if (previous_was_whitespace)
ret.resize(ret.size() - 1);
- return ret;
+ return NormalizeForComparison(ret);
}
// static

Powered by Google App Engine
This is Rietveld 408576698