-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Problem
When there is an invalid character in an HTTP header set via Headers.Builder
, the exception that is thrown indicates the position of the offending character using Hindu-Arabic numbers when the locale is ar_EG
, Arabic (Egypt).
e.g.
java.lang.AssertionError: Unexpected char 0x668 at ٢٥ in header value: Custom Http Client 1.0.0/٨
Since the exception message itself is in English, I would expect any numeric values to be displayed in Western Arabic numbers.
Details
For some locales with the Arabic language, Android will default to displaying numbers using Arabic-Indic numerals when you use code like String.format("%d", 3)
I tested this with okhttp-2.5.0 on desktop JVM as well as Android 6.x and 4.1.2, but the same formatting code exists in okhttp-3.
Test case
Note that I was unable to reproduce the behaviour using javac 1.8.0_60 on Mac OS X, and only on Android. It's possible the locale implementations differ for ar-EG
:
public final class HeadersArEgTest {
@Test public void logMessageWithHinduArabicNumbers() {
final Locale oldLocale = Locale.getDefault();
final Locale newLocale = new Locale("ar", "EG");
final String USER_AGENT = "Custom Http Client 1.0.0/٨"; // final character is invalid
try {
Locale.setDefault(newLocale);
Headers headers = new Headers.Builder()
.set("User-Agent", USER_AGENT)
.build();
} catch (IllegalArgumentException e) {
String msg = e.getMessage();
assertTrue(msg, msg.contains("at " + (USER_AGENT.length()-1) + " in header value"));
} finally {
Locale.setDefault(oldLocale);
}
}
}