Merge lp:~lifeless/python-oops-tools/bug-884265 into lp:python-oops-tools

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: 14
Merged at revision: 13
Proposed branch: lp:~lifeless/python-oops-tools/bug-884265
Merge into: lp:python-oops-tools
Diff against target: 62 lines (+20/-4)
3 files modified
src/oopstools/NEWS.txt (+2/-1)
src/oopstools/oops/models.py (+8/-0)
src/oopstools/oops/test/test_dboopsloader.py (+10/-3)
To merge this branch: bzr merge lp:~lifeless/python-oops-tools/bug-884265
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+81932@code.launchpad.net

Commit message

Handle non-ascii HTTP headers and so forth by url escaping.

Description of the change

Fixup rye's req_vars branch and adjust per wgrants suggestion.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/oopstools/NEWS.txt'
--- src/oopstools/NEWS.txt 2011-11-02 23:19:28 +0000
+++ src/oopstools/NEWS.txt 2011-11-11 03:32:27 +0000
@@ -12,7 +12,8 @@
12 OOPS-prefix (if they had one). (Robert Collins, #884571)12 OOPS-prefix (if they had one). (Robert Collins, #884571)
1313
14* OOPS reports that don't meet the normal rules for req_vars are handled14* OOPS reports that don't meet the normal rules for req_vars are handled
15 a bit better (Robert Collins, William Grant, #885416)15 a bit better.
16 (Robert Collins, William Grant, Roman Yepishev, #885416, #884265)
1617
170.6.1180.6.1
18=====19=====
1920
=== modified file 'src/oopstools/oops/models.py'
--- src/oopstools/oops/models.py 2011-11-02 20:25:00 +0000
+++ src/oopstools/oops/models.py 2011-11-11 03:32:27 +0000
@@ -315,6 +315,14 @@
315 value = ''315 value = ''
316 yield key, value316 yield key, value
317 for key, value in ensure_tuple(req_vars):317 for key, value in ensure_tuple(req_vars):
318 if isinstance(value, str):
319 try:
320 # We can get anything in HTTP headers
321 # Trying to squeeze the bytes into ASCII plane
322 value.decode('ascii')
323 except UnicodeDecodeError:
324 # If that fails, percent-quote them
325 value = urllib.quote(value)
318 if key == 'REQUEST_METHOD':326 if key == 'REQUEST_METHOD':
319 # Truncate the REQUEST_METHOD if it's longer than 10 characters327 # Truncate the REQUEST_METHOD if it's longer than 10 characters
320 # since a str longer than that is not allowed in the DB.328 # since a str longer than that is not allowed in the DB.
321329
=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
--- src/oopstools/oops/test/test_dboopsloader.py 2011-11-02 20:25:00 +0000
+++ src/oopstools/oops/test/test_dboopsloader.py 2011-11-11 03:32:27 +0000
@@ -155,15 +155,22 @@
155 oops = parsed_oops_to_model_oops(report, 'bug_880641')155 oops = parsed_oops_to_model_oops(report, 'bug_880641')
156 self.assertEqual('', oops.pageid)156 self.assertEqual('', oops.pageid)
157157
158 def test_broken_url_handling(self):158 def test_broken_header_handling(self):
159 # This URL is not a valid URL - URL's are a subset of ASCII.
160 broken_url = '/somep\xe1th'159 broken_url = '/somep\xe1th'
161 report = { 'url': broken_url, 'id': 'testbrokenurl'}160 user_agent = '\xf8\x07\x9e'
161 report = { 'url': broken_url,
162 'id': 'testbrokenheader',
163 'req_vars': [
164 [ 'HTTP_USER_AGENT', user_agent ]
165 ]
166 }
162 # We handle such URL's by url quoting them, failing to do so being a167 # We handle such URL's by url quoting them, failing to do so being a
163 # (not uncommon) producer mistake.168 # (not uncommon) producer mistake.
164 expected_url = urllib.quote(broken_url)169 expected_url = urllib.quote(broken_url)
170 expected_user_agent = urllib.quote(user_agent)
165 oops = parsed_oops_to_model_oops(report, 'test_broken_url_handling')171 oops = parsed_oops_to_model_oops(report, 'test_broken_url_handling')
166 self.assertEqual(expected_url, oops.url)172 self.assertEqual(expected_url, oops.url)
173 self.assertEqual(expected_user_agent, oops.user_agent)
167174
168 def test_broken_reqvars_bug_885416(self):175 def test_broken_reqvars_bug_885416(self):
169 # If the tuples in req_vars have only one element the oops still needs176 # If the tuples in req_vars have only one element the oops still needs

Subscribers

People subscribed via source and target branches

to all changes: