Merge lp:~stevenk/launchpad/urifield-with-leading-space into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16118
Proposed branch: lp:~stevenk/launchpad/urifield-with-leading-space
Merge into: lp:launchpad
Diff against target: 121 lines (+17/-28)
4 files modified
lib/lp/app/widgets/textwidgets.py (+2/-2)
lib/lp/registry/browser/productseries.py (+2/-6)
lib/lp/services/fields/__init__.py (+2/-5)
lib/lp/services/fields/doc/uri-field.txt (+11/-15)
To merge this branch: bzr merge lp:~stevenk/launchpad/urifield-with-leading-space
Reviewer Review Type Date Requested Status
Ian Booth (community) Approve
Review via email: mp+128855@code.launchpad.net

Commit message

URIWidget is now a subclass of StrippedTextWidget, so no longer perform the stripping in URIField.

Description of the change

URIWidget is now a subclass of StrippedTextWidget, which means it will strip leading and trailing whitespace. This fixes the root cause for the OOPS, since the database validation function valid_absolute_url() insists unstripped text is invalid, but URIField's validation method strips URIs before validation.

I've cleaned up some whitespace and pylint garbage to force this branch to net-negative, and have cleaned up a very weird copyright header that was completely lowercased.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/widgets/textwidgets.py'
2--- lib/lp/app/widgets/textwidgets.py 2012-06-29 08:40:05 +0000
3+++ lib/lp/app/widgets/textwidgets.py 2012-10-10 03:50:23 +0000
4@@ -144,7 +144,7 @@
5 return value.astimezone(tz).strftime('%Y-%m-%d %H:%M:%S')
6
7
8-class URIWidget(TextWidget):
9+class URIWidget(StrippedTextWidget):
10 """A widget that represents a URI."""
11
12 displayWidth = 44
13@@ -157,7 +157,7 @@
14 def _toFieldValue(self, input):
15 if isinstance(input, list):
16 raise UnexpectedFormData('Only a single value is expected')
17- return TextWidget._toFieldValue(self, input)
18+ return super(URIWidget, self)._toFieldValue(input)
19
20
21 class URIComponentWidget(LowerCaseTextWidget):
22
23=== modified file 'lib/lp/registry/browser/productseries.py'
24--- lib/lp/registry/browser/productseries.py 2012-10-08 04:59:10 +0000
25+++ lib/lp/registry/browser/productseries.py 2012-10-10 03:50:23 +0000
26@@ -1104,8 +1104,7 @@
27 return branch
28
29
30-class ProductSeriesLinkBranchView(ReturnToReferrerMixin,
31- ProductSeriesView,
32+class ProductSeriesLinkBranchView(ReturnToReferrerMixin, ProductSeriesView,
33 LaunchpadEditFormView):
34 """View to set the bazaar branch for a product series."""
35
36@@ -1118,10 +1117,7 @@
37 return 'Link an existing branch to %s %s series' % (
38 self.context.product.displayname, self.context.name)
39
40- @property
41- def page_title(self):
42- """The page title."""
43- return self.label
44+ page_title = label
45
46 @action(_('Update'), name='update')
47 def update_action(self, action, data):
48
49=== modified file 'lib/lp/services/fields/__init__.py'
50--- lib/lp/services/fields/__init__.py 2012-08-14 13:43:24 +0000
51+++ lib/lp/services/fields/__init__.py 2012-10-10 03:50:23 +0000
52@@ -1,7 +1,5 @@
53-# copyright 2009-2010 canonical ltd. this software is licensed under the
54-# gnu affero general public license version 3 (see the file LICENSE).
55-
56-# pylint: disable-msg=E0211,E0213,W0401
57+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
58+# GNU Affero General Public License version 3 (see the file LICENSE).
59
60 __metaclass__ = type
61 __all__ = [
62@@ -626,7 +624,6 @@
63 if input is None:
64 return input
65
66- input = input.strip()
67 try:
68 uri = URI(input)
69 except InvalidURIError as exc:
70
71=== modified file 'lib/lp/services/fields/doc/uri-field.txt'
72--- lib/lp/services/fields/doc/uri-field.txt 2011-12-24 17:49:30 +0000
73+++ lib/lp/services/fields/doc/uri-field.txt 2012-10-10 03:50:23 +0000
74@@ -158,20 +158,11 @@
75 u'http://launchpad.net/'
76
77
78-== Whitespace and null values ==
79-
80-Whitespace is stripped from the value:
81-
82- >>> from zope.publisher.browser import TestRequest
83- >>> from lp.app.validators import LaunchpadValidationError
84- >>> from lp.app.widgets.textwidgets import URIWidget
85+== Null values ==
86+
87+None is an acceptable value for a URI field.
88+
89 >>> field = URIField(__name__='foo', title=u'Foo')
90-
91- >>> field.normalize(' http://www.ubuntu.com/ ')
92- u'http://www.ubuntu.com/'
93-
94-None is an acceptable value for a URI field.
95-
96 >>> print field.normalize(None)
97 None
98
99@@ -187,6 +178,7 @@
100
101 >>> from zope.app.form.interfaces import IInputWidget
102 >>> from zope.component import getMultiAdapter
103+ >>> from lp.app.widgets.textwidgets import URIWidget
104 >>> from lp.services.webapp.servers import LaunchpadTestRequest
105
106 >>> class URIFieldTest(object):
107@@ -202,8 +194,12 @@
108
109 Multiple values will cause an UnexpectedFormData exception:
110
111- >>> widget._toFieldValue(['http://launchpad.net',
112- ... 'http://ubuntu.com'])
113+ >>> widget._toFieldValue(['http://launchpad.net', 'http://ubuntu.com'])
114 Traceback (most recent call last):
115 ...
116 UnexpectedFormData: Only a single value is expected
117+
118+Values with leading and trailing whitespace are stripped.
119+
120+ >>> widget._toFieldValue(' http://www.ubuntu.com/ ')
121+ u'http://www.ubuntu.com/'