Merge lp:~rye/python-oops-tools/trim-url-lp915335 into lp:python-oops-tools

Proposed by Roman Yepishev
Status: Merged
Approved by: Robert Collins
Approved revision: 35
Merged at revision: 36
Proposed branch: lp:~rye/python-oops-tools/trim-url-lp915335
Merge into: lp:python-oops-tools
Diff against target: 51 lines (+18/-1)
2 files modified
src/oopstools/oops/models.py (+2/-1)
src/oopstools/oops/test/test_dboopsloader.py (+16/-0)
To merge this branch: bzr merge lp:~rye/python-oops-tools/trim-url-lp915335
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+116659@code.launchpad.net

Commit message

Trim URL after all the quoting

Description of the change

This fixes the issue when a broken URL expands to more than 500 (MAX_URL_LEN) when quoted and makes the database unhappy.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

cool

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/oopstools/oops/models.py'
2--- src/oopstools/oops/models.py 2011-12-08 04:57:25 +0000
3+++ src/oopstools/oops/models.py 2012-07-25 14:28:57 +0000
4@@ -433,7 +433,7 @@
5 # Trim most_expensive_statements to 200 characters
6 if most_expensive_statement is not None:
7 most_expensive_statement = conform(most_expensive_statement, 200)
8- url = conform(oops.get('url') or '', MAX_URL_LEN)
9+ url = oops.get('url') or ''
10 if type(url) is unicode:
11 # We have gotten a ringer, URL's are bytestrings. Encode to UTF8 to get
12 # a bytestring and urllib.quote to get a url.
13@@ -447,6 +447,7 @@
14 # to quote it to make it a valid URL - this is better than
15 # rejecting the OOPS, or having a URL that isn't in the DB.
16 url = urllib.quote(url)
17+ url = conform(url, MAX_URL_LEN)
18
19 informational = oops.get('informational', 'False').lower() == 'true'
20 oops_date = oops.get('time')
21
22=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
23--- src/oopstools/oops/test/test_dboopsloader.py 2011-11-17 16:11:12 +0000
24+++ src/oopstools/oops/test/test_dboopsloader.py 2012-07-25 14:28:57 +0000
25@@ -36,6 +36,7 @@
26 DBOopsRootDirectory,
27 Oops,
28 parsed_oops_to_model_oops,
29+ MAX_URL_LEN
30 )
31
32
33@@ -253,3 +254,18 @@
34 }
35 oops = parsed_oops_to_model_oops(report, 'bug-891647')
36 self.assertEqual('APPSERVER', oops.appinstance.title)
37+
38+ def test_long_url_bug_915335(self):
39+ # URLs that are longer than 500 characters should be truncated
40+ # at all times.
41+ url = 'http://' + '\xFF' * 250
42+
43+ report = {
44+ 'id': 'OOPS-68383510f5054932567230492013ce91',
45+ 'url': url
46+ }
47+
48+ oops = parsed_oops_to_model_oops(report, 'bug-915335')
49+ oops.save()
50+ self.assertTrue(len(oops.url) < MAX_URL_LEN)
51+

Subscribers

People subscribed via source and target branches

to all changes: