1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

cookie_rewriter: catch CookieError and ignore erroring cookies

This commit is contained in:
Ilya Kreymer 2014-05-15 22:37:08 -07:00
parent 1d8c68b745
commit 5285723ccf
2 changed files with 10 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import Cookie
from Cookie import SimpleCookie, CookieError
#=================================================================
@ -11,10 +11,12 @@ class WbUrlCookieRewriter(object):
self.url_rewriter = url_rewriter
def rewrite(self, cookie_str, header='Set-Cookie'):
cookie = Cookie.SimpleCookie()
cookie.load(cookie_str)
results = []
cookie = SimpleCookie()
try:
cookie.load(cookie_str)
except CookieError:
return results
for name, morsel in cookie.iteritems():
if morsel.get('domain'):

View File

@ -12,6 +12,10 @@ r"""
>>> rewrite_cookie('abc=def; Path=file.html; Expires=Wed, 13 Jan 2021 22:23:01 GMT')
[('Set-Cookie', 'abc=def; Path=/pywb/20131226101010/http://example.com/some/path/file.html')]
# Cookie with invalid chars, not parsed
>>> rewrite_cookie('abc@def=123')
[]
"""