Skip to content

Commit 9574877

Browse files
committed
Different fix for displaying booleans properly in xhtml vs html
Original patch was rendering input tags as xhtml <input .../> rather than html4/5 format as <input ...>.
1 parent 4038ecc commit 9574877

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

CHANGES.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ Fixed:
7070
- French translation gave errors with Python 3 because of ISO-8859-1
7171
character in .mo file header. (Joseph Myers)
7272
- Fix representation of boolean html attributes to be 'required'
73-
rather than the xhtml form of 'required="required"'. Specifiy
74-
attribute value same as attribute name or attribute value of None,
75-
to output attribute as boolean. (John Rouillard)
73+
rather than the xhtml form of 'required="required"'. Specify
74+
(reverted attribute value same as attribute name or) attribute
75+
value of None, to output attribute as boolean. (John Rouillard)
76+
Reverted (part of) this change. It breaks rendering of non-boolean
77+
attributes (like name="name"). So only value of None renders
78+
attribute properly as boolean. (Ralf Schlatterbeck)
7679
- issue2551076 - in responsive template, default searches for bugs and
7780
tasks sets status=new default should be "don't care". (Report:
7881
Ludwig Reiter; Fix: John Rouillard)
@@ -85,9 +88,6 @@ Fixed:
8588
for translations. (Report: John Rouillard; Fix: Christof Meerwald)
8689
- Cleanup code by linting using flake8. (John Rouillard)
8790
- Cleanup code by security linting using bandit. (John Rouillard)
88-
- Revert (part of) the change that optimizes rendering of boolean
89-
attributes in HTML-4. This breaks rendering of non-boolean attributes
90-
(like name="name"). (Ralf Schlatterbeck)
9191

9292
2019-10-23 2.0.0 alpha 0
9393

roundup/cgi/templating.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,10 @@ def html4_cgi_escape_attrs(**attrs):
443443
<input required ..> not <input required="required" ...>
444444
The latter is xhtml. Recognize booleans by:
445445
value is None
446-
value is the same as the attribute
447-
Code can use either method to indicate a pure boolean.
446+
Code can use None to indicate a pure boolean.
448447
'''
449448
return ' '.join(['%s="%s"'%(k,html_escape(str(v), True))
450-
if v != None and k != v else '%s'%(k)
449+
if v != None else '%s'%(k)
451450
for k,v in sorted(attrs.items())])
452451

453452
def xhtml_cgi_escape_attrs(**attrs):
@@ -457,8 +456,7 @@ def xhtml_cgi_escape_attrs(**attrs):
457456
<input required="required" ...> not <input required ..>
458457
The latter is html4 or 5. Recognize booleans by:
459458
value is None
460-
value is the same as the atribute
461-
Code can use either method to indicate a pure boolean.
459+
Code can use None to indicate a pure boolean.
462460
'''
463461
return ' '.join(['%s="%s"'%(k,html_escape(str(v), True))
464462
if v != None else '%s="%s"'%(k,k)
@@ -480,11 +478,12 @@ def __init__(self):
480478
html_version = 'html4'
481479
if hasattr(self._client.instance.config, 'HTML_VERSION'):
482480
html_version = self._client.instance.config.HTML_VERSION
483-
# HTML-4 allows attributes like required=required, so for now
484-
# revert the change that optimizes this and breaks rendering of
485-
# non-boolean attributes (like name="name").
486-
self.input = input_xhtml
487-
self.cgi_escape_attrs=xhtml_cgi_escape_attrs
481+
if html_version == 'xhtml':
482+
self.input = input_xhtml
483+
self.cgi_escape_attrs=xhtml_cgi_escape_attrs
484+
else:
485+
self.input = input_html4
486+
self.cgi_escape_attrs=html4_cgi_escape_attrs
488487
# self._context is used for translations.
489488
# will be initialized by the first call to .gettext()
490489
self._context = None

0 commit comments

Comments
 (0)