diff --git a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java index 21ce6313e..136436dc2 100644 --- a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +++ b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java @@ -3,6 +3,8 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import java.util.Locale; + class ReactNativeBlobUtilConfig { public Boolean fileCache; @@ -33,7 +35,7 @@ class ReactNativeBlobUtilConfig { } if (options.hasKey("binaryContentTypes")) this.binaryContentTypes = options.getArray("binaryContentTypes"); - if (this.path != null && path.toLowerCase().contains("?append=true")) { + if (this.path != null && path.toLowerCase(Locale.ROOT).contains("?append=true")) { this.overwrite = false; } if (options.hasKey("overwrite")) diff --git a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java index 1add27a95..43808e8a1 100644 --- a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +++ b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java @@ -25,6 +25,7 @@ import java.security.MessageDigest; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.UUID; @@ -209,7 +210,7 @@ else if (resolved == null) { return; } - switch (encoding.toLowerCase()) { + switch (encoding.toLowerCase(Locale.ROOT)) { case "base64": promise.resolve(Base64.encodeToString(bytes, Base64.NO_WRAP)); break; @@ -1095,7 +1096,7 @@ protected Integer doInBackground(ReadableArray... paths) { private static byte[] stringToBytes(String data, String encoding) { if (encoding.equalsIgnoreCase("ascii")) { return data.getBytes(Charset.forName("US-ASCII")); - } else if (encoding.toLowerCase().contains("base64")) { + } else if (encoding.toLowerCase(Locale.ROOT).contains("base64")) { return Base64.decode(data, Base64.NO_WRAP); } else if (encoding.equalsIgnoreCase("utf8")) { diff --git a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java index 5b40b1286..2d763183a 100644 --- a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +++ b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java @@ -54,6 +54,7 @@ import java.util.List; import java.util.HashMap; +import java.util.Locale; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLSocketFactory; @@ -120,7 +121,7 @@ enum ResponseFormat { OkHttpClient client; public ReactNativeBlobUtilReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, OkHttpClient client, final Callback callback) { - this.method = method.toUpperCase(); + this.method = method.toUpperCase(Locale.ROOT); this.options = new ReactNativeBlobUtilConfig(options); this.taskId = taskId; this.url = url; @@ -311,14 +312,14 @@ else if (this.options.fileCache) else if (value.equalsIgnoreCase("utf8")) responseFormat = ResponseFormat.UTF8; } else { - builder.header(key.toLowerCase(), value); - mheaders.put(key.toLowerCase(), value); + builder.header(key.toLowerCase(Locale.ROOT), value); + mheaders.put(key.toLowerCase(Locale.ROOT), value); } } } if (method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch")) { - String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase(); + String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase(Locale.ROOT); if (rawRequestBodyArray != null) { requestType = RequestType.Form; @@ -332,7 +333,7 @@ else if (value.equalsIgnoreCase("utf8")) if (rawRequestBody.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX) || rawRequestBody.startsWith(ReactNativeBlobUtilConst.CONTENT_PREFIX)) { requestType = RequestType.SingleFile; - } else if (cType.toLowerCase().contains(";base64") || cType.toLowerCase().startsWith("application/octet")) { + } else if (cType.toLowerCase(Locale.ROOT).contains(";base64") || cType.toLowerCase(Locale.ROOT).startsWith("application/octet")) { cType = cType.replace(";base64", "").replace(";BASE64", ""); if (mheaders.containsKey("content-type")) mheaders.put("content-type", cType); @@ -718,7 +719,7 @@ private boolean isBlobResponse(Response resp) { boolean isCustomBinary = false; if (options.binaryContentTypes != null) { for (int i = 0; i < options.binaryContentTypes.size(); i++) { - if (ctype.toLowerCase().contains(options.binaryContentTypes.getString(i).toLowerCase())) { + if (ctype.toLowerCase(Locale.ROOT).contains(options.binaryContentTypes.getString(i).toLowerCase(Locale.ROOT))) { isCustomBinary = true; break; } @@ -730,13 +731,13 @@ private boolean isBlobResponse(Response resp) { private String getHeaderIgnoreCases(Headers headers, String field) { String val = headers.get(field); if (val != null) return val; - return headers.get(field.toLowerCase()) == null ? "" : headers.get(field.toLowerCase()); + return headers.get(field.toLowerCase(Locale.ROOT)) == null ? "" : headers.get(field.toLowerCase(Locale.ROOT)); } private String getHeaderIgnoreCases(HashMap headers, String field) { String val = headers.get(field); if (val != null) return val; - String lowerCasedValue = headers.get(field.toLowerCase()); + String lowerCasedValue = headers.get(field.toLowerCase(Locale.ROOT)); return lowerCasedValue == null ? "" : lowerCasedValue; } diff --git a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java index 456b9e804..28f002242 100644 --- a/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java +++ b/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java @@ -6,6 +6,7 @@ import java.security.MessageDigest; import java.security.cert.CertificateException; +import java.util.Locale; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; @@ -30,7 +31,7 @@ public static String getMD5(String input) { StringBuilder sb = new StringBuilder(); for (byte b : digest) { - sb.append(String.format("%02x", b & 0xff)); + sb.append(String.format(Locale.ROOT, "%02x", b & 0xff)); } result = sb.toString();