Skip to content

Commit

Permalink
use root locale when converting string case (#33028)
Browse files Browse the repository at this point in the history
Summary:
Not setting locale for language/country neutral operation may cause bug depending on the default locale.
See https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#ROOT

Note: I am just searching for toLowerCase() and toUppercase() in my project's dependencies and send the same PR, in order to just be considered. Although I've seen the lack of explicit locale has caused issues for us, I am not sure if react-native is actually affected. I haven't checked for `String.format()` yet.

Example related issue: joltup/rn-fetch-blob#573

## Changelog

[Android] [Fixed] - Use root locale when converting string case.

Pull Request resolved: #33028

Reviewed By: ShikaSD

Differential Revision: D33943446

Pulled By: cortinico

fbshipit-source-id: d5be9392ea7c21a33436acac5b5e8c50b7c7e31e
  • Loading branch information
halaei authored and facebook-github-bot committed Feb 9, 2022
1 parent 4f42f4d commit 5341ad8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void onReceive(Context context, Intent intent) {
final String bundleFile = subclassTag + "ReactNativeDevBundle.js";
mJSBundleDownloadedFile = new File(applicationContext.getFilesDir(), bundleFile);

final String splitBundlesDir = subclassTag.toLowerCase() + "_dev_js_split_bundles";
final String splitBundlesDir = subclassTag.toLowerCase(Locale.ROOT) + "_dev_js_split_bundles";
mJSSplitBundlesDir = mApplicationContext.getDir(splitBundlesDir, Context.MODE_PRIVATE);

mDefaultNativeModuleCallExceptionHandler = new DefaultNativeModuleCallExceptionHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
Expand Down Expand Up @@ -376,7 +377,9 @@ public void onProgress(
}

RequestBody requestBody;
if (data == null || method.toLowerCase().equals("get") || method.toLowerCase().equals("head")) {
if (data == null
|| method.toLowerCase(Locale.ROOT).equals("get")
|| method.toLowerCase(Locale.ROOT).equals("head")) {
requestBody = RequestBodyUtil.getEmptyBody(method);
} else if (handler != null) {
requestBody = handler.toRequestBody(data, contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.net.Uri;
import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

Expand Down Expand Up @@ -47,7 +48,7 @@ public int getResourceDrawableId(Context context, @Nullable String name) {
if (name == null || name.isEmpty()) {
return 0;
}
name = name.toLowerCase().replace("-", "_");
name = name.toLowerCase(Locale.ROOT).replace("-", "_");

// name could be a resource id.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;

/** Manages instances of TextInput. */
Expand Down Expand Up @@ -569,7 +570,7 @@ public void setCursorColor(ReactEditText view, @Nullable Integer color) {
}

private static boolean shouldHideCursorForEmailTextInput() {
String manufacturer = Build.MANUFACTURER.toLowerCase();
String manufacturer = Build.MANUFACTURER.toLowerCase(Locale.ROOT);
return (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q && manufacturer.contains("xiaomi"));
}

Expand Down

0 comments on commit 5341ad8

Please sign in to comment.