diff --git a/mozilla/content/base/src/nsXMLHttpRequest.cpp b/mozilla/content/base/src/nsXMLHttpRequest.cpp index 8f7a4e11353..8657dfb37a6 100644 --- a/mozilla/content/base/src/nsXMLHttpRequest.cpp +++ b/mozilla/content/base/src/nsXMLHttpRequest.cpp @@ -2218,12 +2218,8 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) if (NS_FAILED(rv)) { contentType.AssignLiteral("application/xml"); specifiedCharset.Truncate(); - haveCharset = PR_FALSE; - } - - if (!haveCharset) { charsetStart = charsetEnd = contentType.Length(); - } + } // 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 diff --git a/mozilla/content/base/test/Makefile.in b/mozilla/content/base/test/Makefile.in index 975af95a132..97725f3cda9 100644 --- a/mozilla/content/base/test/Makefile.in +++ b/mozilla/content/base/test/Makefile.in @@ -166,6 +166,7 @@ _TEST_FILES = test_bug5141.html \ test_bug403841.html \ test_bug409380.html \ test_bug410229.html \ + test_bug413974.html \ test_bug415860.html \ test_bug414190.html \ test_bug414796.html \ diff --git a/mozilla/content/base/test/test_bug413974.html b/mozilla/content/base/test/test_bug413974.html new file mode 100644 index 00000000000..345a6fbfc57 --- /dev/null +++ b/mozilla/content/base/test/test_bug413974.html @@ -0,0 +1,37 @@ + + + +
++ ++ + + diff --git a/mozilla/netwerk/base/public/nsINetUtil.idl b/mozilla/netwerk/base/public/nsINetUtil.idl index c31b5190b2d..016ab1fdf89 100644 --- a/mozilla/netwerk/base/public/nsINetUtil.idl +++ b/mozilla/netwerk/base/public/nsINetUtil.idl @@ -202,17 +202,18 @@ interface nsINetUtil : nsISupports * header, if any. * @param [out] aCharsetStart index of the start of the charset parameter * (the ';' separating it from what came before) in aTypeHeader. - * This is only set if this function returns true. + * If this function returns false, this argument will still be + * set, to the index of the location where a new charset should + * be inserted. * @param [out] aCharsetEnd index of the end of the charset parameter (the - * ';' separating it from what comes after, or inded of the end - * of the string) in aTypeHeader. This is only set if this - * function returns true. + * ';' separating it from what comes after, or the end + * of the string) in aTypeHeader. If this function returns + * false, this argument will still be set, to the index of the + * location where a new charset should be inserted. * * @return whether a charset parameter was found. This can be false even in * cases when parseContentType would claim to have a charset, if the type - * that won out does not have a charset parameter specified, because in this - * case setting the charset does in fact correspond to appending to the - * string. + * that won out does not have a charset parameter specified. */ boolean extractCharsetFromContentType(in AUTF8String aTypeHeader, out AUTF8String aCharset, diff --git a/mozilla/netwerk/base/src/nsIOService.cpp b/mozilla/netwerk/base/src/nsIOService.cpp index 7c00505b8d4..0329c10e002 100644 --- a/mozilla/netwerk/base/src/nsIOService.cpp +++ b/mozilla/netwerk/base/src/nsIOService.cpp @@ -977,7 +977,7 @@ nsIOService::ExtractCharsetFromContentType(const nsACString &aTypeHeader, nsCAutoString ignored; net_ParseContentType(aTypeHeader, ignored, aCharset, aHadCharset, aCharsetStart, aCharsetEnd); - if (*aHadCharset && *aCharsetStart == -1) { + if (*aHadCharset && *aCharsetStart == *aCharsetEnd) { *aHadCharset = PR_FALSE; } return NS_OK; diff --git a/mozilla/netwerk/base/src/nsURLHelper.cpp b/mozilla/netwerk/base/src/nsURLHelper.cpp index cba00537e23..ce9fe849957 100644 --- a/mozilla/netwerk/base/src/nsURLHelper.cpp +++ b/mozilla/netwerk/base/src/nsURLHelper.cpp @@ -830,17 +830,26 @@ net_ParseMediaType(const nsACString &aMediaTypeStr, aContentType.Assign(type, typeEnd - type); ToLowerCase(aContentType); } + if ((!eq && *aHadCharset) || typeHasCharset) { *aHadCharset = PR_TRUE; aContentCharset.Assign(charset, charsetEnd - charset); if (typeHasCharset) { *aCharsetStart = charsetParamStart + aOffset; *aCharsetEnd = charsetParamEnd + aOffset; - } else { - *aCharsetStart = -1; - *aCharsetEnd = -1; } } + // Only set a new charset position if this is a different type + // from the last one we had and it doesn't already have a + // charset param. If this is the same type, we probably want + // to leave the charset position on its first occurrence. + if (!eq && !typeHasCharset) { + PRInt32 charsetStart = PRInt32(paramStart); + if (charsetStart == kNotFound) + charsetStart = flatStr.Length(); + + *aCharsetEnd = *aCharsetStart = charsetStart + aOffset; + } } } diff --git a/mozilla/netwerk/test/unit/test_extract_charset_from_content_type.js b/mozilla/netwerk/test/unit/test_extract_charset_from_content_type.js index 6551adb4166..46497f070cd 100644 --- a/mozilla/netwerk/test/unit/test_extract_charset_from_content_type.js +++ b/mozilla/netwerk/test/unit/test_extract_charset_from_content_type.js @@ -51,10 +51,8 @@ function reset() { function check(aHadCharset, aCharset, aCharsetStart, aCharsetEnd) { do_check_eq(aHadCharset, hadCharset); do_check_eq(aCharset, charset.value); - if (hadCharset) { - do_check_eq(aCharsetStart, charsetStart.value); - do_check_eq(aCharsetEnd, charsetEnd.value); - } + do_check_eq(aCharsetStart, charsetStart.value); + do_check_eq(aCharsetEnd, charsetEnd.value); } function run_test() { @@ -63,36 +61,37 @@ function run_test() { hadCharset = netutil.extractCharsetFromContentType("text/html", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType("TEXT/HTML", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType("text/html, text/html", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType("text/html, text/plain", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 21, 21); hadCharset = netutil.extractCharsetFromContentType('text/html, ', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType('text/html, */*', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType('text/html, foo', charset, charsetStart, charsetEnd); + check(false, "", 9, 9); hadCharset = netutil.extractCharsetFromContentType("text/html; charset=ISO-8859-1", @@ -142,7 +141,7 @@ function run_test() { hadCharset = netutil.extractCharsetFromContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 41, 41); hadCharset = netutil.extractCharsetFromContentType("text/plain, TEXT/HTML; charset='ISO-8859-1', text/html, TEXT/HTML", @@ -162,35 +161,35 @@ function run_test() { hadCharset = netutil.extractCharsetFromContentType("text/plain; param= , text/html", charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 30, 30); hadCharset = netutil.extractCharsetFromContentType('text/plain; param=", text/html"', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 10, 10); hadCharset = netutil.extractCharsetFromContentType('text/plain; param=", \\" , text/html"', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 10, 10); hadCharset = netutil.extractCharsetFromContentType('text/plain; param=", \\" , text/html , "', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 10, 10); hadCharset = netutil.extractCharsetFromContentType('text/plain param=", \\" , text/html , "', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 38, 38); hadCharset = netutil.extractCharsetFromContentType('text/plain charset=UTF8', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 23, 23); hadCharset = netutil.extractCharsetFromContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, charsetStart, charsetEnd); - check(false, ""); + check(false, "", 21, 21); }