Closed
Bug 151912
Opened 23 years ago
Closed 23 years ago
Cookie isn't deleted when setting "expired=1 Jan 1970 00:00:00 GMT"
Categories
(Core :: Networking: Cookies, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: mina86, Assigned: morse)
References
Details
(Whiteboard: checkwin checklinux)
Attachments
(2 files, 1 obsolete file)
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.1a) Gecko/20020611
BuildID: 2002061104
To delete cookie we use:
document.ccokie="name=value; expires=date"
where date is date in the past. When I use thic code in Mozilla, cookie is still
awailable...
Reproducible: Always
Steps to Reproduce:
Try this code:
<script language="javascript" type="text/javascript"><!--
document.write('<b>document.cookie</b> = <b>"',document.cookie,'"</b><br>\n');
document.write('Setting cookie... (TestCookie=TestValue)');
document.cookie="TestCookie=TestValue";
document.write(' Done.<br />\n');
document.write('<b>document.cookie</b> = <b>"',document.cookie,'"</b><br>\n');
var date=new Date(); date.setYear(date.getYear()-1);
document.write('Deleteing cookie... (TestCookie=DEL;
expires='+date.toGMTString()+')');
document.cookie="TestCookie=DEL; expires="+date.toGMTString();
document.write(' Done.<br />\n');
document.write('<b>document.cookie</b> = <b>"',document.cookie,'"</b><br>\n');
//--></script>
Actual Results: we see:
document.cookie = ""
Setting cookie... (TestCookie=TestValue) Done.
document.cookie = "TestCookie=TestValue"
Deleteing cookie... (TestCookie=DEL; expires=Tue, 14 Jun 0101 22:54:44 GMT) Done.
document.cookie = "TestCookie=DEL"
Expected Results: You should repair that problem :)
I have found only one solution. Set value "ThisCookieIsDeleted" and in script,
test if value of cookie, that you have founded, isn't equal to "ThisCookieIsDeleted"
PS. Sorry for my bad english :)
Comment 1•23 years ago
|
||
I have to mark this bug Invalid.
The problem is that you are using the .getYear() method, which does not
return a four-digit year in Mozilla. See bug 22964, bug 45764, and bug 100123.
Use the .getFullYear() method instead, and things should work fine.
I will attach a testcase below showing both .getYear() and .getFullYear().
In IE, they are the same, but Mozilla they are not.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Comment 2•23 years ago
|
||
Comment 3•23 years ago
|
||
Marking Verified Invalid.
Try the testcase above in different browsers. You'll see that
in 2002, (new Date()).getYear() returns "102" in Netscape4.7
and in Mozilla/Netscape 7.
But if you use .getFullYear(), you will get "2002" as desired.
Note also, .setFullYear() is preferred over .setYear()
Status: RESOLVED → VERIFIED
Reporter | ||
Comment 4•23 years ago
|
||
Well, I haven't fought about this :)
But any way: Why this:
var date=new Date(); date.setTime(0);
document.cookie="TestCookie=DEL; expires="+date.toGMTString();
or this:
theDoc.cookie="TestCookie=DEL; expires=Thu, 1 Jan 1970 00:00:00 GMT";
code dosen't work. However this code:
theDoc.cookie="TestCookie=DEL; expires=Thu, 1 Jan 1970 00:00:01 GMT";
works...
Status: VERIFIED → UNCONFIRMED
Resolution: INVALID → ---
Comment 5•23 years ago
|
||
OK, this is now a Cookies question; reassigning to Cookies component -
Assignee: rogerl → morse
Component: JavaScript Engine → Cookies
QA Contact: pschwartau → tever
Summary: Cookie isn't deleted when setting "expired=..." → Cookie isn't deleted when setting "expired=1 Jan 1970 00:00:00 GMT"
Assignee | ||
Comment 6•23 years ago
|
||
Without testing this out, I'm going to take a stab as to what I think is
happening. By setting the date to 1 Jan 1970 00:00:00, you are giving it a time
of 0 since this is the very beginning of the epoch. And a time of 0 is
interpreted (rightly so) as a session cookie.
Does the cookie manager indicate that this cookie expires at the end of the
session? And, equivalently, does the cookie vanish the next time you launch the
browser? If so, then this is the correct behavior.
Reporter | ||
Comment 7•23 years ago
|
||
It looks like you have right. After Mozilla's restart cookie disappears :).
Any way: IMHO it's a BUG! IMHO time of 0 shouldn't be interprated as end of session. When I want to set a session cookie I put no "expires=...".
PS. In 2nd and 3rd example from my previous comment "theDoc" means "document" :p
hmm... ok, looks like using the date to indicate session cookies is problematic.
marking CONFIRMED. reducing severity.
Severity: normal → minor
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 9•23 years ago
|
||
Checkin to bug 156725 fixed this problem.
Verified fixed, per attached testcase.
Comment 10•23 years ago
|
||
Sorry, previous testcase got mangled by bugzilla.
Attachment #111735 -
Attachment is obsolete: true
Comment 11•23 years ago
|
||
Marking RESOLVED/FIXED
Status: NEW → RESOLVED
Closed: 23 years ago → 23 years ago
Resolution: --- → FIXED
Comment 12•22 years ago
|
||
*** Bug 208046 has been marked as a duplicate of this bug. ***
Comment 13•22 years ago
|
||
VERIFIED: Mozilla 1.4b, Mach-O.
I also found that this test case could use some checking code for the javascript
cookie permissions.
If anyone has any code handy that can check for that, please email me.
Otherwise, I'll hack it together as I test the other platforms and hack my
javascript skills up to snuff.
Whiteboard: checkwin checklinux
You need to log in
before you can comment on or make changes to this bug.
Description
•