Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<String, String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down