diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index d539f43637c4..8e5db40498a5 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -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 diff --git a/netwerk/base/src/nsURLHelper.cpp b/netwerk/base/src/nsURLHelper.cpp index 22022220e662..61e7fbb92219 100644 --- a/netwerk/base/src/nsURLHelper.cpp +++ b/netwerk/base/src/nsURLHelper.cpp @@ -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++; diff --git a/netwerk/test/unit/test_extract_charset_from_content_type.js b/netwerk/test/unit/test_extract_charset_from_content_type.js index 46497f070cd2..47d9d2289f25 100644 --- a/netwerk/test/unit/test_extract_charset_from_content_type.js +++ b/netwerk/test/unit/test_extract_charset_from_content_type.js @@ -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); diff --git a/netwerk/test/unit/test_parse_content_type.js b/netwerk/test/unit/test_parse_content_type.js index 327a5d486fc2..3ee2c243a9b7 100644 --- a/netwerk/test/unit/test_parse_content_type.js +++ b/netwerk/test/unit/test_parse_content_type.js @@ -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); }