Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement loose cooking parsing #1255

Merged
merged 1 commit into from Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/jsdom.js
Expand Up @@ -36,7 +36,7 @@ exports.getVirtualConsole = function (window) {
};

exports.createCookieJar = function () {
return new CookieJar();
return new CookieJar(null, { looseMode: true });
};

exports.nodeLocation = function (node) {
Expand Down Expand Up @@ -200,7 +200,7 @@ exports.env = exports.jsdom.env = function () {
proxy: config.proxy || null
};

config.cookieJar = config.cookieJar || new CookieJar();
config.cookieJar = config.cookieJar || exports.createCookieJar();

resourceLoader.download(config.url, options, config.cookieJar, null, (err, responseText, res) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/jsdom/level1/core.js
Expand Up @@ -753,7 +753,7 @@ core.Document = function Document(options) {
this._attached = true;
this._readonly = false;
this._currentScript = null;
this._cookieJar = options.cookieJar === undefined ? new CookieJar() : options.cookieJar;
this._cookieJar = options.cookieJar === undefined ? new CookieJar(null, { looseMode: true }) : options.cookieJar;

this._contentType = options.contentType;
if (this._contentType === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,7 @@
"parse5": "^1.4.2",
"request": "^2.55.0",
"symbol-tree": ">= 3.1.0 < 4.0.0",
"tough-cookie": "^2.0.0",
"tough-cookie": "^2.2.0",
"webidl-conversions": "^2.0.0",
"whatwg-url-compat": "~0.6.5",
"xml-name-validator": ">= 2.0.1 < 3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/level2/html.js
Expand Up @@ -2488,7 +2488,7 @@ exports.tests = {

var ret = doc.cookie = null;
test.equal(ret, null, "cookieLink");
test.equal(doc.cookie, vcookie, "cookieLink");
test.equal(doc.cookie, vcookie + "; null", "cookieLink"); // yes, this is actually how this should behave


test.done();
Expand Down
30 changes: 20 additions & 10 deletions test/living-html/cookie.js
Expand Up @@ -17,7 +17,8 @@ const testCookies = [
"Test7=Secure; expires=Wed, 13-Jan-2051 22:23:01 GMT; path=/; Secure",
"Test8=Expired; expires=Wed, 13-Jan-1977 22:23:01 GMT; path=/",
"Test9=Duplicate; One=More; expires=Wed, 13-Jan-2051 22:23:01 GMT; path=/",
"Test10={\"prop1\":5,\"prop2\":\"value\"}; expires=Wed, 13-Jan-2051 22:23:01 GMT; path=/"
"Test10={\"prop1\":5,\"prop2\":\"value\"}; expires=Wed, 13-Jan-2051 22:23:01 GMT; path=/",
"Malformed; expires=Wed, 13-Jan-2051 22:23:01 GMT; path=/"
];

function assertCookies(t, actualCookieStr, expectedCookies) {
Expand Down Expand Up @@ -104,7 +105,8 @@ exports["Set cookie by client"] = t => {
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
}
Expand All @@ -121,7 +123,8 @@ exports["Set cookie by page request"] = t => {
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
}
Expand All @@ -145,7 +148,8 @@ exports["Set cookie by resource request"] = t => {
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
};
Expand All @@ -168,7 +172,8 @@ exports["Set cookie by XHR"] = t => {
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
};
Expand Down Expand Up @@ -212,7 +217,8 @@ exports["Send Cookies header via resource request"] = t => {
"Test2=PathMatch",
"Test6=HttpOnly",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
};
Expand All @@ -236,7 +242,8 @@ exports["Send Cookies header via XHR"] = t => {
"Test2=PathMatch",
"Test6=HttpOnly",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
};
Expand Down Expand Up @@ -265,7 +272,8 @@ exports["Share cookies with <iframe>"] = t => {
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);
t.done();
};
Expand Down Expand Up @@ -326,14 +334,16 @@ exports["options.cookieJar"] = t => {
"Test2=PathMatch",
"Test6=HttpOnly",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);

assertCookies(t, window.document.cookie, [
"Test1=Basic",
"Test2=PathMatch",
"Test9=Duplicate",
"Test10={\"prop1\":5,\"prop2\":\"value\"}"
"Test10={\"prop1\":5,\"prop2\":\"value\"}",
"Malformed"
]);

t.done();
Expand Down