Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9266847e authored by Kenny Root's avatar Kenny Root Committed by Android (Google) Code Review
Browse files

Merge "Fix crash determining direction of invalid locale"

parents df60dc32 49e3b372
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -71,8 +71,9 @@ public class LocaleUtil {
        if (localeWithSubtags == null) return getLayoutDirectionFromFirstChar(locale);

        // Need to check if we can extract the script subtag. For example, "Latn" in  "en_Latn_US"
        if (localeWithSubtags.charAt(2) != UNDERSCORE_CHAR ||
                localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) {
        if (localeWithSubtags.length() <= 7
                || localeWithSubtags.charAt(2) != UNDERSCORE_CHAR
                || localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) {
            return getLayoutDirectionFromFirstChar(locale);
        }
        // Extract the script subtag
+5 −0
Original line number Diff line number Diff line
@@ -193,5 +193,10 @@ public class LocaleUtilTest extends AndroidTestCase {
        locale = new Locale("uz_Arab", "AF");
        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            LocaleUtil.getLayoutDirectionFromLocale(locale));

        // Locale without a real language
        locale = new Locale("zz");
        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            LocaleUtil.getLayoutDirectionFromLocale(locale));
    }
}