Handle HTTP header parameters with empty values better

This handles the null issue reported.

Closes #26598

BUG= https://github.com/dart-lang/sdk/issues/26958
R=floitsch@google.com

Review URL: https://codereview.chromium.org/2225003002 .
This commit is contained in:
Søren Gjesse 2016-08-08 16:35:15 +02:00
parent e6241bc12d
commit f9404b969b
3 changed files with 23 additions and 2 deletions

View file

@ -14,6 +14,7 @@
* `Socket.connect` with source-address argument is now non-blocking
on Mac. Was already non-blocking on all other platforms.
* Report a better error when a bind fails because of a bad source address.
* Handle HTTP header `charset` parameter with empty value.
### Strong Mode

View file

@ -760,12 +760,12 @@ class _HeaderValue implements HeaderValue {
}
maybeExpect("=");
skipWS();
if(done()) {
if (done()) {
parameters[name] = null;
return;
}
String value = parseParameterValue();
if (name == 'charset' && this is _ContentType) {
if (name == 'charset' && this is _ContentType && value != null) {
// Charset parameter of ContentTypes are always lower-case.
value = value.toLowerCase();
}

View file

@ -380,6 +380,11 @@ void testContentType() {
" text/html ; charset = utf-8 ; xxx=yyy ");
check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"});
contentType = ContentType.parse("text/html; charset=;");
check(contentType, "text", "html", {"charset": null});
contentType = ContentType.parse("text/html; charset;");
check(contentType, "text", "html", {"charset": null});
// Test builtin content types.
check(ContentType.TEXT, "text", "plain", {"charset": "utf-8"});
check(ContentType.HTML, "text", "html", {"charset": "utf-8"});
@ -387,6 +392,20 @@ void testContentType() {
check(ContentType.BINARY, "application", "octet-stream");
}
void testKnownContentTypes() {
// Well known content types used by the VM service.
ContentType.parse('text/html; charset=UTF-8');
ContentType.parse('application/dart; charset=UTF-8');
ContentType.parse('application/javascript; charset=UTF-8');
ContentType.parse('text/css; charset=UTF-8');
ContentType.parse('image/gif');
ContentType.parse('image/png');
ContentType.parse('image/jpeg');
ContentType.parse('image/jpeg');
ContentType.parse('image/svg+xml');
ContentType.parse('text/plain');
}
void testContentTypeCache() {
_HttpHeaders headers = new _HttpHeaders("1.1");
headers.set(HttpHeaders.CONTENT_TYPE, "text/html");
@ -570,6 +589,7 @@ main() {
testEnumeration();
testHeaderValue();
testContentType();
testKnownContentTypes();
testContentTypeCache();
testCookie();
testInvalidCookie();