Skip to content

Commit 5341ad8

Browse files
halaeifacebook-github-bot
authored andcommitted
use root locale when converting string case (#33028)
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
1 parent 4f42f4d commit 5341ad8

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void onReceive(Context context, Intent intent) {
198198
final String bundleFile = subclassTag + "ReactNativeDevBundle.js";
199199
mJSBundleDownloadedFile = new File(applicationContext.getFilesDir(), bundleFile);
200200

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

204204
mDefaultNativeModuleCallExceptionHandler = new DefaultNativeModuleCallExceptionHandler();

ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.ArrayList;
3131
import java.util.HashSet;
3232
import java.util.List;
33+
import java.util.Locale;
3334
import java.util.Set;
3435
import java.util.concurrent.TimeUnit;
3536
import okhttp3.Call;
@@ -376,7 +377,9 @@ public void onProgress(
376377
}
377378

378379
RequestBody requestBody;
379-
if (data == null || method.toLowerCase().equals("get") || method.toLowerCase().equals("head")) {
380+
if (data == null
381+
|| method.toLowerCase(Locale.ROOT).equals("get")
382+
|| method.toLowerCase(Locale.ROOT).equals("head")) {
380383
requestBody = RequestBodyUtil.getEmptyBody(method);
381384
} else if (handler != null) {
382385
requestBody = handler.toRequestBody(data, contentType);

ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.net.Uri;
1313
import androidx.annotation.Nullable;
1414
import java.util.HashMap;
15+
import java.util.Locale;
1516
import java.util.Map;
1617
import javax.annotation.concurrent.ThreadSafe;
1718

@@ -47,7 +48,7 @@ public int getResourceDrawableId(Context context, @Nullable String name) {
4748
if (name == null || name.isEmpty()) {
4849
return 0;
4950
}
50-
name = name.toLowerCase().replace("-", "_");
51+
name = name.toLowerCase(Locale.ROOT).replace("-", "_");
5152

5253
// name could be a resource id.
5354
try {

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.lang.reflect.Field;
7676
import java.util.HashMap;
7777
import java.util.LinkedList;
78+
import java.util.Locale;
7879
import java.util.Map;
7980

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

571572
private static boolean shouldHideCursorForEmailTextInput() {
572-
String manufacturer = Build.MANUFACTURER.toLowerCase();
573+
String manufacturer = Build.MANUFACTURER.toLowerCase(Locale.ROOT);
573574
return (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q && manufacturer.contains("xiaomi"));
574575
}
575576

0 commit comments

Comments
 (0)