This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Cookie module does not parse date
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, insomnike, manlioperillo
Priority: normal Keywords:

Created on 2004-06-02 09:02 by manlioperillo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cookie.txt manlioperillo, 2004-06-02 09:02 regex pattern for Cookie module
Messages (4)
msg20971 - (view) Author: Manlio Perillo (manlioperillo) Date: 2004-06-02 09:02
>>> sys.version
'2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit
(Intel)]'
>>> sys.platform
'win32'
>>> sys.getwindowsversion()
(5, 1, 2600, 2, '')

Hi.
The standard Cookie module does not parse date string.

Here is and example:

>>> import Cookie
>>> s = 'Set-Cookie: key=value; path=/; expires=Fri,
21-May-2004 10:40:51 GMT'
>>> c = Cookie.BaseCookie(s)
>>> print c
Set-Cookie: key=value; expires=Fri,; Path=/;


In the attached file I have reported the correct (I
think) regex pattern.



Thanks and Regards  Manlio Perillo
msg20972 - (view) Author: Aaron Brady (insomnike) Date: 2004-06-05 13:43
Logged In: YES 
user_id=1057404

This bug is in error; RFC2109 specifies the BNF grammar as:

   av-pairs        =       av-pair *(";" av-pair)
   av-pair         =       attr ["=" value]        ;
optional value
   attr            =       token
   value           =       word
   word            =       token | quoted-string

If you surround the date in double quotes, as per the RFC,
then the above works correctly.
msg20973 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 20:50
Logged In: YES 
user_id=11375

Closing as 'not a bug'.  This decision could be reversed if there's some 
common application or software that returns cookies without quoting the 
date properly.
msg20974 - (view) Author: Manlio Perillo (manlioperillo) Date: 2004-06-06 11:09
Logged In: YES 
user_id=1054957

insomnike wrote that RFC2109 requires double quotes.
This is right, but many servers follow the Netscape spec.

Moreover (as I can see) the same Cookie module follow the
Netscape date spec!

>>> import Cookie
>>> c = Cookie.SimpleCookie()
>>> c['key'] = 'value'
>>> c['key']['expires'] = 10
>>> c.output()
'Set-Cookie: key=value; expires=Sun, 06-Jun-2004 10:36:24 GMT;'
>>> s = c.output()
>>> nc = Cookie.SimpleCookie(s)
>>> nc.output()
'Set-Cookie: key=value; expires=Sun,;'


Thanks and regards   Manlio Perillo
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40325
2004-06-02 09:02:41manlioperillocreate