Bug 700589 - Fix Content-Type parser to treat single quote as regular character instead of a delimiter. r=jduell r=bz

This commit is contained in:
julian.reschke@gmx.de 2011-11-29 14:06:32 -08:00
Родитель beed8018d0
Коммит 8bbf8765f8
4 изменённых файлов: 34 добавлений и 14 удалений

Просмотреть файл

@ -2491,6 +2491,16 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
&haveCharset, &charsetStart,
&charsetEnd);
if (NS_SUCCEEDED(rv)) {
// special case: the extracted charset is quoted with single quotes
// -- for the purpose of preserving what was set we want to handle
// them as delimiters (although they aren't really)
if (specifiedCharset.Length() >= 2 &&
specifiedCharset.First() == '\'' &&
specifiedCharset.Last() == '\'') {
specifiedCharset = Substring(specifiedCharset, 1,
specifiedCharset.Length() - 2);
}
// If the content-type the page set already has a charset parameter,
// and it's the same charset, up to case, as |charset|, just send the
// page-set content-type header. Apparently at least

Просмотреть файл

@ -808,7 +808,7 @@ net_FindMediaDelimiter(const nsCString& flatStr,
do {
// searchStart points to the spot from which we should start looking
// for the delimiter.
const char delimStr[] = { delimiter, '"', '\'', '\0' };
const char delimStr[] = { delimiter, '"', '\0' };
PRUint32 curDelimPos = flatStr.FindCharInSet(delimStr, searchStart);
if (curDelimPos == PRUint32(kNotFound))
return flatStr.Length();
@ -893,7 +893,7 @@ net_ParseMediaType(const nsACString &aMediaTypeStr,
// '(' in the trailing trim set to catch media-type comments, which are
// not at all standard, but may occur in rare cases.
charset = net_FindCharNotInSet(charset, charsetEnd, HTTP_LWS);
if (*charset == '"' || *charset == '\'') {
if (*charset == '"') {
charsetEnd =
start + net_FindStringEnd(flatStr, charset - start, *charset);
charset++;

Просмотреть файл

@ -121,15 +121,15 @@ function run_test() {
hadCharset =
netutil.extractCharsetFromContentType("text/html; charset='ISO-8859-1'",
charset, charsetStart, charsetEnd);
check(true, "ISO-8859-1", 9, 31);
check(true, "'ISO-8859-1'", 9, 31);
hadCharset =
netutil.extractCharsetFromContentType("text/html; charset='ISO-8859-1', text/html",
netutil.extractCharsetFromContentType("text/html; charset=\"ISO-8859-1\", text/html",
charset, charsetStart, charsetEnd);
check(true, "ISO-8859-1", 9, 31);
hadCharset =
netutil.extractCharsetFromContentType("text/html; charset='ISO-8859-1', text/html; charset=UTF8",
netutil.extractCharsetFromContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8",
charset, charsetStart, charsetEnd);
check(true, "UTF8", 42, 56);
@ -144,17 +144,17 @@ function run_test() {
check(false, "", 41, 41);
hadCharset =
netutil.extractCharsetFromContentType("text/plain, TEXT/HTML; charset='ISO-8859-1', text/html, TEXT/HTML",
netutil.extractCharsetFromContentType("text/plain, TEXT/HTML; charset=\"ISO-8859-1\", text/html, TEXT/HTML",
charset, charsetStart, charsetEnd);
check(true, "ISO-8859-1", 21, 43);
hadCharset =
netutil.extractCharsetFromContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset=\'ISO-8859-1\'; param2="charset=UTF16", text/html, TEXT/HTML',
netutil.extractCharsetFromContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML',
charset, charsetStart, charsetEnd);
check(true, "ISO-8859-1", 43, 65);
hadCharset =
netutil.extractCharsetFromContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset=\'ISO-8859-1\'; param2=charset=UTF16, text/html, TEXT/HTML',
netutil.extractCharsetFromContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML',
charset, charsetStart, charsetEnd);
check(true, "ISO-8859-1", 41, 63);

Просмотреть файл

@ -56,6 +56,7 @@ function check(aType, aCharset, aHadCharset) {
function run_test() {
var netutil = Components.classes["@mozilla.org/network/util;1"]
.getService(Components.interfaces.nsINetUtil);
type = netutil.parseContentType("text/html", charset, hadCharset);
check("text/html", "", false);
@ -88,13 +89,13 @@ function run_test() {
type = netutil.parseContentType("text/html; charset='ISO-8859-1'",
charset, hadCharset);
check("text/html", "ISO-8859-1", true);
check("text/html", "'ISO-8859-1'", true);
type = netutil.parseContentType("text/html; charset='ISO-8859-1', text/html",
type = netutil.parseContentType("text/html; charset=\"ISO-8859-1\", text/html",
charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/html; charset='ISO-8859-1', text/html; charset=UTF8",
type = netutil.parseContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8",
charset, hadCharset);
check("text/html", "UTF8", true);
@ -104,13 +105,13 @@ function run_test() {
type = netutil.parseContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, hadCharset);
check("text/plain", "", true);
type = netutil.parseContentType("text/plain, TEXT/HTML; charset='ISO-8859-1', text/html, TEXT/HTML", charset, hadCharset);
type = netutil.parseContentType("text/plain, TEXT/HTML; charset=ISO-8859-1, text/html, TEXT/HTML", charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset=\'ISO-8859-1\'; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
type = netutil.parseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset=\'ISO-8859-1\'; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset);
type = netutil.parseContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/plain; param= , text/html", charset, hadCharset);
@ -134,4 +135,13 @@ function run_test() {
type = netutil.parseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "", false);
// Bug 700589
// check that single quote doesn't confuse parsing of subsequent parameters
type = netutil.parseContentType("text/plain; x='; charset=\"UTF-8\"", charset, hadCharset);
check("text/plain", "UTF-8", true);
// check that single quotes do not get removed from extracted charset
type = netutil.parseContentType("text/plain; charset='UTF-8'", charset, hadCharset);
check("text/plain", "'UTF-8'", true);
}