Skip to content

Commit 2620bcb

Browse files
committed
issue2550795: @dispname query args in page.html search links
not valid html. Some queries with names that include spaces are not properly url encoded/quoted. I.E. a space should be replaced with %20. Fixes to allow a url_query method to be applied to HTMLStringProperty to properly quote string values passed as part of a url.
1 parent efdd31a commit 2620bcb

File tree

9 files changed

+43
-4
lines changed

9 files changed

+43
-4
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ Fixed:
303303
the subject when encountering a double prefix, e.g.
304304
Subject: [frobulated] [frobulatedagain] this part would be lost
305305
(Ralf Schlatterbeck)
306+
- issue2550795: @dispname query args in page.html search links
307+
not valid html. Some queries with names that include spaces are not
308+
properly url encoded/quoted. I.E. a space should be replaced with
309+
%20. Fixes to allow a url_query method to be applied to
310+
HTMLStringProperty to properly quote string values passed as part of
311+
a url.
306312

307313
2016-01-11: 1.5.1
308314

doc/customizing.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,9 @@ multiline only on String properties - render a multiline form edit
24222422
field for the property
24232423
email only on String properties - render the value of the property
24242424
as an obscured email address
2425+
url_quote only on String properties. It quotes any characters in the
2426+
string so it is safe to use in a url. E.G. a space is
2427+
replaced with %20.
24252428
confirm only on Password properties - render a second form edit field
24262429
for the property, used for confirmation that the user typed
24272430
the password correctly. Generates a field with name

doc/upgrading.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ html/_generic* templates into your subdirectory so that missing
186186
templates (e.g. a missing caller.edit.html template) can be satisfied
187187
by the _generic.edit.html template.
188188

189+
Properly quote query dispname (displayed name) in page.html
190+
-----------------------------------------------------------
191+
192+
A new method has been added to HTMLStringProperty called url_quote.
193+
The default templates have been updated to use this in the "Your
194+
Query" section of the trackers html/page.html file. You will want to
195+
change your template. Lines starting with - are the original line and
196+
you want to change it to match the line starting with the + (remove
197+
the + from the line)::
198+
199+
<tal:block tal:repeat="qs request/user/queries">
200+
- <a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name}"
201+
+ <a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name/url_quote}"
202+
tal:content="qs/name">link</a><br>
203+
</tal:block>
204+
205+
Find the tal:repeat line that loops over all queries. Then
206+
change the value assigned to @dispname in the href attribute from
207+
${qs/name} to ${qs/name/url_quote}. Note that you should *not* change
208+
the value for tal:content.
209+
189210
Schema change to allow "Show Unassigned" issues link to work for Anonymous user
190211
-------------------------------------------------------------------------------
191212

roundup/cgi/templating.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,10 @@ def _hyper_repl_rst(self, match):
13991399
# just return the matched text
14001400
return match.group(0)
14011401

1402+
def url_quote(self):
1403+
""" Return the string in plain format but escaped for use in a url """
1404+
return urllib.quote(self.plain())
1405+
14021406
def hyperlinked(self):
14031407
""" Render a "hyperlinked" version of the text """
14041408
return self.plain(hyperlink=1)

share/roundup/templates/classic/html/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h2><span metal:define-slot="body_title">body title</span></h2>
5454
<span i18n:translate=""
5555
><b>Your Queries</b> (<a href="query?@template=edit">edit</a>)</span><br>
5656
<tal:block tal:repeat="qs request/user/queries">
57-
<a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name}"
57+
<a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name/url_quote}"
5858
tal:content="qs/name">link</a><br>
5959
</tal:block>
6060
</p>

share/roundup/templates/devel/html/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ <h1><a href="/">Roundup Demo Tracker</a></h1>
210210
<span i18n:translate=""><b>Your Queries</b> (<a class="nomargin" href="query?@template=edit">edit</a>)</span><br/>
211211
<ul tal:repeat="qs request/user/queries">
212212
<li>
213-
<a tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name}" tal:content="qs/name">link</a>
213+
<a tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name/url_quote}" tal:content="qs/name">link</a>
214214
</li>
215215
</ul>
216216
</li>

share/roundup/templates/minimal/html/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h2><span metal:define-slot="body_title">body title</span></h2>
5454
<span i18n:translate=""
5555
><b>Your Queries</b> (<a href="query?@template=edit">edit</a>)</span><br>
5656
<tal:block tal:repeat="qs request/user/queries">
57-
<a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name}"
57+
<a href="#" tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name/url_quote}"
5858
tal:content="qs/name">link</a><br>
5959
</tal:block>
6060
</p>

share/roundup/templates/responsive/html/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
<span i18n:translate=""><b>Your Queries</b> (<a class="nomargin" href="query?@template=edit">edit</a>)</span><br/>
228228
<ul tal:repeat="qs request/user/queries">
229229
<li>
230-
<a tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name}" tal:content="qs/name">link</a>
230+
<a tal:attributes="href string:${qs/klass}?${qs/url}&@dispname=${qs/name/url_quote}" tal:content="qs/name">link</a>
231231
</li>
232232
</ul>
233233
</li>

test/test_templating.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def lookup(key) :
104104
cls = HTMLClass(self.client, "issue")
105105
cls["nosy"]
106106

107+
def test_string_url_quote(self):
108+
''' test that urlquote quotes the string '''
109+
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'test string< foo@bar')
110+
self.assertEqual(p.url_quote(), 'test%20string%3C%20foo%40bar')
111+
107112
def test_url_match(self):
108113
'''Test the URL regular expression in StringHTMLProperty.
109114
'''

0 commit comments

Comments
 (0)