Bug 1448891 - Lowercase private use tags in MozLocale in accordance with BCP47. r?jfkthame draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Tue, 27 Mar 2018 07:11:27 +0200
changeset 773099 523975342c44b80c0e3a15b246053e7d8614fe5e
parent 772310 b99844d179cacf74a5d39ad23429be91e989c331
push id104120
push userbmo:gandalf@aviary.pl
push dateTue, 27 Mar 2018 10:36:29 +0000
reviewersjfkthame
bugs1448891
milestone61.0a1
Bug 1448891 - Lowercase private use tags in MozLocale in accordance with BCP47. r?jfkthame MozReview-Commit-ID: 2mpCbJlevu4
intl/locale/MozLocale.cpp
intl/locale/tests/gtest/TestMozLocale.cpp
--- 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"));
 }