Skip to content

Commit

Permalink
Fix for InterpolatorType crash
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Emily Janzer authored and facebook-github-bot committed Oct 10, 2018
1 parent a82f6e1 commit 01a1004
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 01a1004

Please sign in to comment.