Skip to content

Commit

Permalink
Fixed some incorrect header string key types
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jun 4, 2013
1 parent 97a0821 commit f3435a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions werkzeug/testsuite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def test_redirect(self):
self.assert_equal(resp.headers['Location'], 'http://example.com/')
self.assert_equal(resp.status_code, 305)

def test_redirect_no_unicode_header_keys(self):
# Make sure all headers are native keys. This was a bug at one point
# due to an incorrect conversion.
resp = utils.redirect('http://example.com/', 305)
for key, value in resp.headers.items():
self.assert_equal(type(key), str)
self.assert_equal(type(value), text_type)
self.assert_equal(resp.headers['Location'], 'http://example.com/')
self.assert_equal(resp.status_code, 305)

def test_redirect_xss(self):
location = 'http://example.com/?xss="><script>alert(1)</script>'
resp = utils.redirect(location)
Expand Down
4 changes: 2 additions & 2 deletions werkzeug/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,12 +1023,12 @@ def get_wsgi_headers(self, environ):
current_url = iri_to_uri(current_url)
location = url_join(current_url, location)
if location != old_location:
headers[u'Location'] = location
headers['Location'] = location

# make sure the content location is a URL
if content_location is not None and \
isinstance(content_location, text_type):
headers[u'Content-Location'] = iri_to_uri(content_location)
headers['Content-Location'] = iri_to_uri(content_location)

# remove entity headers and set content length to zero if needed.
# Also update content_length accordingly so that the automatic
Expand Down

0 comments on commit f3435a3

Please sign in to comment.