{"action":"created","issue":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/1027","labels_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1027/labels{/name}","comments_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1027/comments","events_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1027/events","html_url":"https://github.com/tmpvar/jsdom/issues/1027","id":57833450,"number":1027,"title":"Expired cookie is still present in document.cookie","user":{"login":"rmurphey","id":58987,"avatar_url":"https://avatars.githubusercontent.com/u/58987?v=3","gravatar_id":"","url":"https://api.github.com/users/rmurphey","html_url":"https://github.com/rmurphey","followers_url":"https://api.github.com/users/rmurphey/followers","following_url":"https://api.github.com/users/rmurphey/following{/other_user}","gists_url":"https://api.github.com/users/rmurphey/gists{/gist_id}","starred_url":"https://api.github.com/users/rmurphey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmurphey/subscriptions","organizations_url":"https://api.github.com/users/rmurphey/orgs","repos_url":"https://api.github.com/users/rmurphey/repos","events_url":"https://api.github.com/users/rmurphey/events{/privacy}","received_events_url":"https://api.github.com/users/rmurphey/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tmpvar/jsdom/labels/bug","name":"bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-02-16T17:48:14Z","updated_at":"2015-02-17T20:30:02Z","closed_at":null,"body":"jsdom version: 3.1.1\r\n\r\nI ran into a bug that is alluded to in #310 and referenced in ScottHamper/Cookies#37 and jmeas/backbone.simple-auth#1: A cookie set with an expiration date in the past -- as [recommended on MDN](https://developer.mozilla.org/en-US/docs/Web/API/document.cookie#Removing_a_cookie) as the way to delete a cookie -- is still present in `document.cookie` inside jsdom. \r\n\r\njsdom test case:\r\n\r\n```js\r\nvar jsdom = require('jsdom');\r\n\r\njsdom.env('<p>expired cookie bug</p>', function (err, window) {\r\n  var doc = window.document;\r\n\r\n  function create(name, value, days) {\r\n    var date = new Date();\r\n    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));\r\n    var expires = days ? ';expires=' + date.toGMTString() : '';\r\n\r\n    var c = name + '=' +\r\n      encodeURIComponent(value) +\r\n      expires +\r\n      ';path=/';\r\n\r\n    doc.cookie = c;\r\n  }\r\n\r\n  // set a cookie that expires in 10 days\r\n  create('testcookie1', '1', 10);\r\n  console.log('unexpired cookie is present', !!doc.cookie.match('testcookie1=1'));\r\n\r\n  // set a cookie that has already expired\r\n  create('testcookie2', '', -1);\r\n  console.log('expired cookie is present', !!doc.cookie.match('testcookie2'));\r\n});\r\n```\r\n\r\nThis results in the following output:\r\n\r\n```\r\nunexpired cookie is present true\r\nexpired cookie is present true\r\n```\r\n\r\nHere is a browser test case:\r\n\r\n```js\r\nvar doc = window.document;\r\n\r\nfunction create(name, value, days) {\r\n  var date = new Date();\r\n  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));\r\n  var expires = days ? ';expires=' + date.toGMTString() : '';\r\n\r\n  var c = name + '=' +\r\n    encodeURIComponent(value) +\r\n    expires +\r\n    ';path=/';\r\n\r\n  doc.cookie = c;\r\n}\r\n\r\n// set a cookie that expires in 10 days\r\ncreate('testcookie1', '1', 10);\r\nconsole.log('unexpired cookie is present', !!doc.cookie.match('testcookie1=1'));\r\n\r\n// set a cookie that has already expired\r\ncreate('testcookie2', '', -1);\r\nconsole.log('expired cookie is present', !!doc.cookie.match('testcookie2'));\r\n```\r\n\r\nThe output is as expected:\r\n\r\n```\r\nunexpired cookie is present true\r\nexpired cookie is present false\r\n```"},"comment":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/comments/74746715","html_url":"https://github.com/tmpvar/jsdom/issues/1027#issuecomment-74746715","issue_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1027","id":74746715,"user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"created_at":"2015-02-17T20:30:02Z","updated_at":"2015-02-17T20:30:02Z","body":"Would love to farm out cookie handling to another module. Happy to take anyone's patches that does that :). Either that or we can keep patching our current implementation.\r\n\r\nAlso worth checking out: https://github.com/assaf/zombie/blob/master/src/cookies.js"}}