зеркало из https://github.com/mozilla/gecko-dev.git
Bug 826159 - Turn nsICookie.value into AUTF8String. r=bz
This commit is contained in:
Родитель
9015c8a2c6
Коммит
280752aa61
|
@ -5,7 +5,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=784367
|
|||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for non-ASCII document.cookie</title>
|
||||
<title>Test for non-ASCII cookie values</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
|
@ -18,12 +18,37 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=784367
|
|||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for non-ASCII document.cookie **/
|
||||
/** Test for non-ASCII cookie values **/
|
||||
|
||||
var [Cc, Ci] = [SpecialPowers.Cc, SpecialPowers.Ci];
|
||||
|
||||
var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
|
||||
function getCookieFromManager() {
|
||||
var values = [];
|
||||
var host = location.hostname;
|
||||
var path = location.pathname;
|
||||
path = path.substring(0, path.lastIndexOf("/") + 1);
|
||||
var e = cm.enumerator;
|
||||
while (e.hasMoreElements()) {
|
||||
var cookie = e.getNext().QueryInterface(Ci.nsICookie);
|
||||
if (!cookie) {
|
||||
break;
|
||||
}
|
||||
if (host != cookie.host || path != cookie.path) {
|
||||
continue;
|
||||
}
|
||||
values.push(cookie.name + "=" + cookie.value);
|
||||
}
|
||||
return values.join("; ");
|
||||
}
|
||||
|
||||
var c = document.cookie;
|
||||
is(document.cookie, 'abc=012©ABC\ufffdDEF', "document.cookie should be decoded as UTF-8");
|
||||
is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
|
||||
var newCookie = 'def=∼≩≭≧∯≳≲≣∽≸≸∺≸∠≯≮≥≲≲≯≲∽≡≬≥≲≴∨∱∩∾';
|
||||
document.cookie = newCookie;
|
||||
is(document.cookie, c + '; ' + newCookie, "document.cookie should be encoded as UTF-8");
|
||||
is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
|
||||
var date1 = new Date();
|
||||
date1.setTime(0);
|
||||
document.cookie = newCookie + 'def=;expires=' + date1.toGMTString();
|
||||
|
|
|
@ -54,6 +54,10 @@ CPPSRCS += \
|
|||
CookieServiceChild.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(topsrcdir)/intl/uconv/src \
|
||||
$(NULL)
|
||||
|
||||
# FIXME/bug 575918: out-of-process xpcshell is broken on OS X
|
||||
ifneq ($(OS_ARCH),Darwin)
|
||||
XPCSHELL_TESTS += test/unit_ipc
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsCookie.h"
|
||||
#include "nsUTF8ConverterService.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -77,8 +78,14 @@ nsCookie::Create(const nsACString &aName,
|
|||
bool aIsSecure,
|
||||
bool aIsHttpOnly)
|
||||
{
|
||||
// Ensure mValue contains a valid UTF-8 sequence. Otherwise XPConnect will
|
||||
// truncate the string after the first invalid octet.
|
||||
nsUTF8ConverterService converter;
|
||||
nsAutoCString aUTF8Value;
|
||||
converter.ConvertStringToUTF8(aValue, "UTF-8", false, true, 1, aUTF8Value);
|
||||
|
||||
// find the required string buffer size, adding 4 for the terminating nulls
|
||||
const uint32_t stringLength = aName.Length() + aValue.Length() +
|
||||
const uint32_t stringLength = aName.Length() + aUTF8Value.Length() +
|
||||
aHost.Length() + aPath.Length() + 4;
|
||||
|
||||
// allocate contiguous space for the nsCookie and its strings -
|
||||
|
@ -90,7 +97,7 @@ nsCookie::Create(const nsACString &aName,
|
|||
// assign string members
|
||||
char *name, *value, *host, *path, *end;
|
||||
name = static_cast<char *>(place) + sizeof(nsCookie);
|
||||
StrBlockCopy(aName, aValue, aHost, aPath,
|
||||
StrBlockCopy(aName, aUTF8Value, aHost, aPath,
|
||||
name, value, host, path, end);
|
||||
|
||||
// If the creationTime given to us is higher than the running maximum, update
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
typedef long nsCookieStatus;
|
||||
typedef long nsCookiePolicy;
|
||||
|
||||
[scriptable, uuid(E9FCB9A4-D376-458f-B720-E65E7DF593BC)]
|
||||
[scriptable, uuid(8684966b-1877-4f0f-8155-be4490b96bf7)]
|
||||
|
||||
interface nsICookie : nsISupports {
|
||||
|
||||
|
@ -26,7 +26,7 @@ interface nsICookie : nsISupports {
|
|||
/**
|
||||
* the cookie value
|
||||
*/
|
||||
readonly attribute ACString value;
|
||||
readonly attribute AUTF8String value;
|
||||
|
||||
/**
|
||||
* true if the cookie is a domain cookie, false otherwise
|
||||
|
|
Загрузка…
Ссылка в новой задаче