[android] #4354 - Ensuring userAgent is always ASCII formatted

This commit is contained in:
Brad Leege
2016-04-04 17:32:40 -05:00
parent 11f7db293e
commit 001d24dc33
2 changed files with 20 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.internal.Util;
/**
* Singleton control center for managing Telemetry Data.
@@ -160,6 +161,8 @@ public class MapboxEventManager {
// Build User Agent
if (TextUtils.equals(userAgent, BuildConfig.MAPBOX_EVENTS_USER_AGENT_BASE) && !TextUtils.isEmpty(appName) && !TextUtils.isEmpty(versionName)) {
userAgent = appName + "/" + versionName + "/" + versionCode + " " + userAgent;
// Ensure that only ASCII characters are sent
userAgent = Util.toHumanReadableAscii(userAgent);
}
} catch (Exception e) {

View File

@@ -0,0 +1,17 @@
package com.mapbox.mapboxsdk.telemetry;
import org.junit.Test;
import okhttp3.internal.Util;
import static junit.framework.Assert.assertEquals;
public class HttpTransportTest {
@Test
public void testNonAsciiUserAgent() {
final String swedishUserAgent = "Sveriges Fjäll/1.0/1 MapboxEventsAndroid/4.0.0-SNAPSHOT";
final String asciiVersion = "Sveriges Fj?ll/1.0/1 MapboxEventsAndroid/4.0.0-SNAPSHOT";
assertEquals("asciiVersion and swedishUserAgent should match", asciiVersion, Util.toHumanReadableAscii(swedishUserAgent));
}
}