diff options
| -rw-r--r-- | core/java/android/util/LocaleUtil.java | 5 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/util/LocaleUtilTest.java | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/core/java/android/util/LocaleUtil.java b/core/java/android/util/LocaleUtil.java index 4511d94..e767a85 100644 --- a/core/java/android/util/LocaleUtil.java +++ b/core/java/android/util/LocaleUtil.java @@ -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 diff --git a/core/tests/coretests/src/android/util/LocaleUtilTest.java b/core/tests/coretests/src/android/util/LocaleUtilTest.java index a3b4948..5aa99c1 100644 --- a/core/tests/coretests/src/android/util/LocaleUtilTest.java +++ b/core/tests/coretests/src/android/util/LocaleUtilTest.java @@ -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)); } } |
