Skip to content

Commit

Permalink
- remove duplicate test
Browse files Browse the repository at this point in the history
 - add in check for special '$' behavior.
 - coverage of the LenientCookie parser
  • Loading branch information
Unknown committed Dec 15, 2011
1 parent a803709 commit 3067786
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/zope/publisher/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,19 @@ def _BaseCookie__ParseString(self, str, patt=Cookie._CookiePattern):
# mechanism as a whole. See RFC 2109.
# (Does anyone care?)
if M:
M[ K[1:] ] = V
try:
M[ K[1:] ] = V
except Cookie.CookieError:
# We don't care.
pass
elif K.lower() in Cookie.Morsel._reserved:
if M:
M[ K ] = Cookie._unquote(V)
else:
rval, cval = self.value_decode(V)
try:
self._BaseCookie__set(K, rval, cval)
M = self[K]
except Cookie.CookieError, e:
eventlog.warning(e)

Expand Down
12 changes: 6 additions & 6 deletions src/zope/publisher/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def testRequestLocale(self):
def testCookies(self):
cookies = {
'HTTP_COOKIE':
'foo=bar; path=/; spam="eggs", this="Should be accepted"'
'foo=bar; path=/; spam="eggs", this="Should be fine"; $t="f"'
}
req = self._createRequest(extra_env=cookies)

Expand All @@ -454,12 +454,15 @@ def testCookies(self):
self.assertEquals(req.cookies[u'spam'], u'eggs')
self.assertEquals(req[u'spam'], u'eggs')

self.assertEquals(req.cookies[u'this'], u'Should be accepted')
self.assertEquals(req[u'this'], u'Should be accepted')
self.assertEquals(req.cookies[u'this'], u'Should be fine')
self.assertEquals(req[u'this'], u'Should be fine')

# Reserved key
self.failIf(req.cookies.has_key('path'))

self.failIf(req.cookies.has_key('t'))
self.failIf(req.cookies.has_key('$t'))

def testCookieErrorToLog(self):
# Cookies accompanying an invalid one shouldn't be trashed.
cookies = {
Expand All @@ -477,9 +480,6 @@ def testCookieErrorToLog(self):
self.failIf(req.cookies.has_key('ldap/OU'))
self.failIf(req.has_key('ldap/OU'))

# Reserved key
self.failIf(req.cookies.has_key('path'))

def testCookiesUnicode(self):
# Cookie values are assumed to be UTF-8 encoded
cookies = {'HTTP_COOKIE': r'key="\342\230\243";'}
Expand Down

0 comments on commit 3067786

Please sign in to comment.