зеркало из https://github.com/mozilla/pjs.git
Add the charset right after the type, before all other params, if there is no
existing charset in the type. Bug 413974, r=biesi, sr=sicking, a=beltzner
This commit is contained in:
Родитель
7f35fd390a
Коммит
7566776699
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=413974
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 413974</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=413974">Mozilla Bug 413974</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 413974 **/
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("POST", window.location.href);
|
||||
req.setRequestHeader("Content-Type", "text/plain; boundary=01234567890");
|
||||
req.send("Some text");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
is(req.channel
|
||||
.QueryInterface(Components.interfaces.nsIHttpChannel)
|
||||
.getRequestHeader("Content-Type"),
|
||||
"text/plain; charset=UTF-8; boundary=01234567890",
|
||||
"Charset should come before boundary");
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче