Bug 1448891 - Lowercase private use tags in MozLocale in accordance with BCP47. r?jfkthame
MozReview-Commit-ID: 2mpCbJlevu4
--- a/intl/locale/MozLocale.cpp
+++ b/intl/locale/MozLocale.cpp
@@ -58,17 +58,17 @@ Locale::Locale(const nsACString& aLocale
* --- 0 -- --- 1 -- -- 2 - -- 3 - -- 4 -- --- x --- ---- 6 ---
*/
for (const nsACString& subTag : normLocale.Split('-')) {
auto slen = subTag.Length();
if (slen > 8) {
mIsValid = false;
return;
} else if (position == 6) {
- mPrivateUse.AppendElement(subTag);
+ ToLowerCase(*mPrivateUse.AppendElement(subTag));
} else if (subTag.LowerCaseEqualsLiteral("x")) {
position = 6;
} else if (position == 0) {
if (slen < 2 || slen > 3) {
mIsValid = false;
return;
}
mLanguage = subTag;
--- a/intl/locale/tests/gtest/TestMozLocale.cpp
+++ b/intl/locale/tests/gtest/TestMozLocale.cpp
@@ -58,16 +58,23 @@ TEST(Intl_Locale_Locale, MatchesRange) {
Locale loc3 = Locale("en");
ASSERT_FALSE(loc == loc3);
ASSERT_TRUE(loc.Matches(loc3, false, true));
ASSERT_FALSE(loc.Matches(loc3, true, false));
ASSERT_FALSE(loc.Matches(loc3, false, false));
ASSERT_TRUE(loc.Matches(loc3, true, true));
}
+TEST(Intl_Locale_Locale, Variants) {
+ Locale loc = Locale("en-US-UniFon-BasicEng");
+
+ // Make sure that we canonicalize and sort variant tags
+ ASSERT_TRUE(loc.AsString().Equals("en-US-basiceng-unifon"));
+}
+
TEST(Intl_Locale_Locale, PrivateUse) {
Locale loc = Locale("x-test");
ASSERT_TRUE(loc.IsValid());
ASSERT_TRUE(loc.GetLanguage().Equals(""));
ASSERT_TRUE(loc.GetScript().Equals(""));
ASSERT_TRUE(loc.GetRegion().Equals(""));
ASSERT_TRUE(loc.GetVariants().Length() == 0);
@@ -79,14 +86,15 @@ TEST(Intl_Locale_Locale, PrivateUse) {
ASSERT_TRUE(loc2.IsValid());
ASSERT_TRUE(loc2.GetLanguage().Equals("fr"));
ASSERT_TRUE(loc2.GetScript().Equals(""));
ASSERT_TRUE(loc2.GetRegion().Equals(""));
ASSERT_TRUE(loc2.GetVariants().Length() == 0);
ASSERT_TRUE(loc2.AsString().Equals("fr-x-test"));
- // Make sure that we preserve private use tags order.
- Locale loc3 = Locale("fr-x-foo-bar-baz");
+ // Make sure that we canonicalize private use tags
+ // and preserve their order.
+ Locale loc3 = Locale("fr-x-foo-bAr-BaZ");
ASSERT_TRUE(loc3.IsValid());
ASSERT_TRUE(loc3.AsString().Equals("fr-x-foo-bar-baz"));
}