From 01a1004808928e29a6d6c698b3b18312fed17a02 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Wed, 10 Oct 2018 15:29:45 -0700 Subject: [PATCH] Fix for InterpolatorType crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: We're currently getting a redbox in Turkish when we try to convert the string 'easeInEaseOut' to an InterpolatorType. This is because I use toLowerCase() to compare the string without setting a locale; in Turkish, the capital letter 'I' doesn't convert to 'i' when you lowercase it, but rather to 'ı' (http://www.i18nguy.com/unicode/turkish-i18n.html). Passing in a locale param to `toLowerCase()` fixes it. Also updating the test. Differential Revision: D10315474 fbshipit-source-id: 54be3ff1d3f91cb2ec765ff705ac364b976b8c6f --- .../react/uimanager/layoutanimation/InterpolatorType.java | 4 +++- .../uimanager/layoutanimation/InterpolatorTypeTest.java | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/InterpolatorType.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/InterpolatorType.java index e92b6b54f3d467..9334ab28acfc1d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/InterpolatorType.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/InterpolatorType.java @@ -5,6 +5,8 @@ package com.facebook.react.uimanager.layoutanimation; +import java.util.Locale; + /** * Enum representing the different interpolators that can be used in layout animation configuration. */ @@ -16,7 +18,7 @@ SPRING; public static InterpolatorType fromString(String name) { - switch (name.toLowerCase()) { + switch (name.toLowerCase(Locale.US)) { case "linear": return LINEAR; case "easein": diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/InterpolatorTypeTest.java b/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/InterpolatorTypeTest.java index b28fad7bb3ff92..291d1c4facb4a8 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/InterpolatorTypeTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/InterpolatorTypeTest.java @@ -8,6 +8,7 @@ package com.facebook.react.uimanager.layoutanimation; import com.facebook.react.uimanager.layoutanimation.InterpolatorType; +import java.util.Locale; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -32,6 +33,12 @@ public void testOtherCases() { assertThat(InterpolatorType.fromString("easeineaseout")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT); } + @Test + public void testLocales() { + Locale.setDefault(Locale.forLanguageTag("tr-TR")); + assertThat(InterpolatorType.fromString("easeInEaseOut")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT); + } + @Test(expected = IllegalArgumentException.class) public void testInvalidInterpolatorTypes() throws IllegalArgumentException { InterpolatorType.fromString("ease_in_ease_out");