Skip to content

Fix issue with UTF8 strings in RC SDK 19.0.0 #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2019
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 @@ -46,10 +46,10 @@
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler.FetchResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -178,7 +178,7 @@ FetchResponse fetch(
byte[] requestBody =
createFetchRequestBody(instanceId, instanceIdToken, analyticsUserProperties)
.toString()
.getBytes();
.getBytes("utf-8");
setFetchRequestBody(urlConnection, requestBody);

urlConnection.connect();
Expand Down Expand Up @@ -321,10 +321,11 @@ private void setFetchRequestBody(HttpURLConnection urlConnection, byte[] request

private JSONObject getFetchResponseBody(URLConnection urlConnection)
throws IOException, JSONException {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader br =
new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "utf-8"));
StringBuilder responseStringBuilder = new StringBuilder();
int current = 0;
while ((current = in.read()) != -1) {
while ((current = br.read()) != -1) {
responseStringBuilder.append((char) current);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ public void setUp() throws Exception {
hasChangeResponseBody =
new JSONObject()
.put(STATE, "UPDATE")
.put(ENTRIES, new JSONObject().put("key_1", "value_1").put("key2", "value_2"))
.put(
ENTRIES,
new JSONObject()
.put("key_1", "value_1")
.put("key2", "value_2")
.put("key_emoji", "\uD83C\uDDFA\uD83C\uDDF3"))
.put(
EXPERIMENT_DESCRIPTIONS,
new JSONArray()
Expand Down