1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-17 08:42:25 +03:00

Tweak error copy, add a couple tests

This commit is contained in:
Patrick Forhan
2016-01-14 14:12:52 -06:00
parent 396afbe490
commit efbbb47626
2 changed files with 21 additions and 1 deletions

View File

@@ -334,4 +334,24 @@ public final class HeadersTest {
} catch (IndexOutOfBoundsException expected) {
}
}
@Test public void builderRejectsUnicodeInHeaderName() {
try {
new Headers.Builder().add("héader1", "value1");
fail("Should have complained about invalid name");
} catch (IllegalArgumentException expected) {
assertEquals("Unexpected char 0xe9 at 1 in header name: héader1",
expected.getMessage());
}
}
@Test public void builderRejectsUnicodeInHeaderValue() {
try {
new Headers.Builder().add("header1", "valué1");
fail("Should have complained about invalid value");
} catch (IllegalArgumentException expected) {
assertEquals("Unexpected char 0xe9 at 4 in header1 value: valué1",
expected.getMessage());
}
}
}

View File

@@ -281,7 +281,7 @@ public final class Headers {
char c = value.charAt(i);
if (c <= '\u001f' || c >= '\u007f') {
throw new IllegalArgumentException(String.format(
"Unexpected char %#04x at %d in header value: %s", (int) c, i, value));
"Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value));
}
}
}