Skip to content

Commit d8871e1

Browse files
committed
Add test and changelog for html boolean fix.
1 parent 63c9e3a commit d8871e1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Fixed:
5555
rejected when confirming registration. (John Rouillard)
5656
- French translation gave errors with Python 3 because of ISO-8859-1
5757
character in .mo file header. (Joseph Myers)
58+
- Fix representation of boolean html attributes to be 'required'
59+
rather than the xhtml form of 'required="required"'. Specifiy
60+
attribute value same as attribute name or attribute value of None,
61+
to output attribute as boolean. (John Rouillard)
5862

5963
2019-10-23 2.0.0 alpha 0
6064

test/test_templating.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,43 @@ def t(s): return p.hyper_re.sub(p._hyper_repl, s)
296296
ae(t('http://roundup.net/%c/' % c),
297297
'<a href="http://roundup.net/%c/" rel="nofollow noopener">http://roundup.net/%c/</a>' % (c, c))
298298

299+
def test_input_html4(self):
300+
# boolean attributes are just the attribute name
301+
# indicate with attr=None or attr="attr"
302+
# e.g. disabled
303+
304+
input=input_html4(required=None, size=30)
305+
self.assertEqual(input, '<input required size="30" type="text">')
306+
307+
input=input_html4(required="required", size=30)
308+
self.assertEqual(input, '<input required size="30" type="text">')
309+
310+
attrs={"required": None, "class": "required", "size": 30}
311+
input=input_html4(**attrs)
312+
self.assertEqual(input, '<input class="required" required size="30" type="text">')
313+
314+
attrs={"disabled": "disabled", "class": "required", "size": 30}
315+
input=input_html4(**attrs)
316+
self.assertEqual(input, '<input class="required" disabled size="30" type="text">')
317+
318+
def test_input_xhtml(self):
319+
# boolean attributes are attribute name="attribute name"
320+
# indicate with attr=None or attr="attr"
321+
# e.g. disabled="disabled"
322+
input=input_xhtml(required=None, size=30)
323+
self.assertEqual(input, '<input required="required" size="30" type="text"/>')
324+
325+
input=input_xhtml(required="required", size=30)
326+
self.assertEqual(input, '<input required="required" size="30" type="text"/>')
327+
328+
attrs={"required": None, "class": "required", "size": 30}
329+
input=input_xhtml(**attrs)
330+
self.assertEqual(input, '<input class="required" required="required" size="30" type="text"/>')
331+
332+
attrs={"disabled": "disabled", "class": "required", "size": 30}
333+
input=input_xhtml(**attrs)
334+
self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text"/>')
335+
299336
r'''
300337
class HTMLPermissions:
301338
def is_edit_ok(self):

0 commit comments

Comments
 (0)