Ticket #10188: 10188.diff
File 10188.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/http/__init__.py
263 263 cookiedict[key] = c.get(key).value 264 264 return cookiedict 265 265 266 class BadHeaderError(ValueError): 267 pass 268 266 269 class HttpResponse(object): 267 270 """A basic HTTP response, with content and dictionary-accessed headers.""" 268 271 … … 301 304 def _convert_to_ascii(self, *values): 302 305 """Converts all values to ascii strings.""" 303 306 for value in values: 307 if '\n' in value or '\r' in value: 308 raise BadHeaderError("Header values can't contain newlines (got %r)" % (value)) 304 309 if isinstance(value, unicode): 305 310 try: 306 311 yield value.encode('us-ascii') -
tests/regressiontests/httpwrappers/tests.py
444 444 ... 445 445 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 446 446 447 # Bug #10188: Do not allow newlines in headers (CR or LF) 448 >>> r['test\\rstr'] = 'test' 449 Traceback (most recent call last): 450 ... 451 BadHeaderError: Header values can't contain newlines (got 'test\\rstr') 452 453 >>> r['test\\nstr'] = 'test' 454 Traceback (most recent call last): 455 ... 456 BadHeaderError: Header values can't contain newlines (got 'test\\nstr') 457 447 458 # 448 459 # Regression test for #8278: QueryDict.update(QueryDict) 449 460 # -
docs/ref/request-response.txt
445 445 >>> response = HttpResponse() 446 446 >>> response['Pragma'] = 'no-cache' 447 447 448 .. versionadded:: 1.1 449 450 HTTP headers cannot contain newlines. An attempt to set a header containing a 451 newline character (CR or LF) will raise ``BadHeaderError`` 452 448 453 Telling the browser to treat the response as a file attachment 449 454 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 450 455