summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:40:34 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:40:34 +0000
commit0934e35f418895925345d059490e27d643db1133 (patch)
tree5474ce837529bb6a0db600b68d54e759999812d5
parent914c6b0f6eb98617009f94f71da7e64b5733d63f (diff)
downloadchromium_src-0934e35f418895925345d059490e27d643db1133.zip
chromium_src-0934e35f418895925345d059490e27d643db1133.tar.gz
chromium_src-0934e35f418895925345d059490e27d643db1133.tar.bz2
Make ToUpper and ToLower properly handle embedded NULLs in the input.
BUG=72517 TEST=included unit test Review URL: http://codereview.chromium.org/6625046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77502 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/base/l10n/l10n_util.cc6
-rw-r--r--ui/base/l10n/l10n_util_unittest.cc15
2 files changed, 19 insertions, 2 deletions
diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc
index 42cf591..eb4e959 100644
--- a/ui/base/l10n/l10n_util.cc
+++ b/ui/base/l10n/l10n_util.cc
@@ -781,7 +781,8 @@ string16 TruncateString(const string16& string, size_t length) {
string16 ToLower(const string16& string) {
icu::UnicodeString lower_u_str(
- icu::UnicodeString(string.c_str()).toLower(icu::Locale::getDefault()));
+ icu::UnicodeString(FALSE, string.c_str(), string.size()).toLower(
+ icu::Locale::getDefault()));
string16 result;
lower_u_str.extract(0, lower_u_str.length(),
WriteInto(&result, lower_u_str.length() + 1));
@@ -790,7 +791,8 @@ string16 ToLower(const string16& string) {
string16 ToUpper(const string16& string) {
icu::UnicodeString upper_u_str(
- icu::UnicodeString(string.c_str()).toUpper(icu::Locale::getDefault()));
+ icu::UnicodeString(FALSE, string.c_str(), string.size()).toUpper(
+ icu::Locale::getDefault()));
string16 result;
upper_u_str.extract(0, upper_u_str.length(),
WriteInto(&result, upper_u_str.length() + 1));
diff --git a/ui/base/l10n/l10n_util_unittest.cc b/ui/base/l10n/l10n_util_unittest.cc
index 5678314..511cb69 100644
--- a/ui/base/l10n/l10n_util_unittest.cc
+++ b/ui/base/l10n/l10n_util_unittest.cc
@@ -330,6 +330,21 @@ TEST_F(L10nUtilTest, LocaleDisplayName) {
result = l10n_util::GetDisplayNameForLocale("es-419", "en", false);
EXPECT_EQ(ASCIIToUTF16("Spanish (Latin America)"), result);
+
+ // ToUpper and ToLower should work with embedded NULLs.
+ const size_t length_with_null = 4;
+ char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' };
+ string16 string16_with_null(buf_with_null, length_with_null);
+
+ string16 upper_with_null = l10n_util::ToUpper(string16_with_null);
+ ASSERT_EQ(length_with_null, upper_with_null.size());
+ EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' &&
+ upper_with_null[2] == 0 && upper_with_null[3] == 'B');
+
+ string16 lower_with_null = l10n_util::ToLower(upper_with_null);
+ ASSERT_EQ(length_with_null, upper_with_null.size());
+ EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' &&
+ lower_with_null[2] == 0 && lower_with_null[3] == 'b');
}
TEST_F(L10nUtilTest, GetParentLocales) {