Ticket #13007: 13007.diff
File 13007.diff, 2.2 KB (added by , 14 years ago) |
---|
-
django/http/__init__.py
366 366 367 367 return val, encoded 368 368 369 def load(self, rawdata, ignore_parse_errors=False): 370 if ignore_parse_errors: 371 self.bad_cookies = [] 372 self._BaseCookie__set = self._loose_set 373 SimpleCookie.load(self, rawdata) 374 if ignore_parse_errors: 375 self._BaseCookie__set = self._strict_set 376 for key in self.bad_cookies: 377 del self[key] 378 379 _strict_set = BaseCookie._BaseCookie__set 380 381 def _loose_set(self, key, real_value, coded_value): 382 try: 383 self._strict_set(key, real_value, coded_value) 384 except CookieError: 385 self.bad_cookies.append(key) 386 dict.__setitem__(self, key, None) 387 388 369 389 def parse_cookie(cookie): 370 390 if cookie == '': 371 391 return {} 372 392 if not isinstance(cookie, BaseCookie): 373 393 try: 374 394 c = CompatCookie() 375 c.load(cookie )395 c.load(cookie, ignore_parse_errors=True) 376 396 except CookieError: 377 397 # Invalid cookie 378 398 return {} -
tests/regressiontests/httpwrappers/tests.py
1 1 import copy 2 2 import pickle 3 3 4 from django.http import QueryDict, HttpResponse, CompatCookie, BadHeaderError 4 from django.http import QueryDict, HttpResponse, CompatCookie, BadHeaderError, \ 5 parse_cookie 5 6 from django.utils import unittest 6 7 7 8 class QueryDictTests(unittest.TestCase): … … 264 265 c2 = CompatCookie() 265 266 c2.load(c.output()) 266 267 self.assertEqual(c['test'].value, c2['test'].value) 268 269 def test_nonstandard_keys(self): 270 """ 271 Test that a single non-standard cookie name doesn't affect all cookies. 272 """ 273 self.assert_('good_cookie' in parse_cookie('good_cookie=yes;bad:cookie=yes').keys())