Bug 1618034 - Strip private subtags in nsLanguageAtomService::GetUncachedLanguageGroup so that we can parse the standard subtags and use the proper font prefs. r=zbraniecki
authorJonathan Kew <jkew@mozilla.com>
Thu, 23 Apr 2020 10:04:18 +0000
changeset 525583 961700e5d48a292ca8d15f974729946227374359
parent 525582 97746752b28722cf211936074133ae771f760fec
child 525584 0aa77ee04caae3d4081bbc992f2d962d3c9ec449
push id37341
push usercbrindusan@mozilla.com
push dateThu, 23 Apr 2020 21:43:09 +0000
treeherdermozilla-central@ff7eec7be698 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszbraniecki
bugs1618034
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1618034 - Strip private subtags in nsLanguageAtomService::GetUncachedLanguageGroup so that we can parse the standard subtags and use the proper font prefs. r=zbraniecki Differential Revision: https://phabricator.services.mozilla.com/D72050
intl/locale/nsLanguageAtomService.cpp
--- a/intl/locale/nsLanguageAtomService.cpp
+++ b/intl/locale/nsLanguageAtomService.cpp
@@ -165,17 +165,29 @@ nsStaticAtom* nsLanguageAtomService::Get
       }
       // Do the slow ascii-case-insensitive comparison just if needed.
       nsDependentAtomString string(langGroup);
       if (string.EqualsASCII(langStr.get(), langStr.Length())) {
         return langGroup;
       }
     }
   } else {
-    // If the lang code can be parsed as BCP47, look up its (likely) script
+    // If the lang code can be parsed as BCP47, look up its (likely) script.
+
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=1618034:
+    // First strip any private subtags that would cause Locale to reject the
+    // tag as non-wellformed.
+    nsACString::const_iterator start, end;
+    langStr.BeginReading(start);
+    langStr.EndReading(end);
+    if (FindInReadable(NS_LITERAL_CSTRING("-x-"), start, end)) {
+      // The substring we want ends at the beginning of the "-x-" subtag.
+      langStr.Truncate(start.get() - langStr.BeginReading());
+    }
+
     Locale loc(langStr);
     if (loc.IsWellFormed()) {
       // Fill in script subtag if not present.
       if (loc.GetScript().IsEmpty()) {
         loc.Maximize();
       }
       // Traditional Chinese has separate prefs for Hong Kong / Taiwan;
       // check the region subtag.