diff --git a/intl/locale/nsLanguageAtomService.cpp b/intl/locale/nsLanguageAtomService.cpp index b52093e18d05..f24e980e24a0 100644 --- a/intl/locale/nsLanguageAtomService.cpp +++ b/intl/locale/nsLanguageAtomService.cpp @@ -170,7 +170,19 @@ nsStaticAtom* nsLanguageAtomService::GetUncachedLanguageGroup( } } } 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.