Commit 9f8a761b authored by Romain Courteaud's avatar Romain Courteaud

[Formulator] Fix end tags generation to match HTML5 specifications

Do not silently skip content for void elements.
Do not add not requested \n which create unwanted textNode.
parent 2840e0ed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testEmptyDivGeneration</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Gadget Field</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Gadget Field</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/FooModule_createObjects?num:int=1;portal_type=Bar</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Created Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/Zuite_waitForActivities</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Done.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/0/Bar_viewGadgetField</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_file']</td>
<td></td>
</tr>
<!-- The p.clear must not be interpreted inside the div.input
This issue came from html5 invalide <div/> -->
<tr>
<td>assertElementNotPresent</td>
<td>//div[@class='input']/p[@class='clear']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='field']/p[@class='clear']</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
......@@ -45,7 +45,7 @@ class TestAudioField(ERP5TypeTestCase):
self.field.values['default'] = 'Audio content'
self.assertEqual('<audio preload="preload" src="Audio content" ' +
'controls="controls" >\nYour browser does not ' +
'controls="controls" >Your browser does not ' +
'support audio tag.</audio>', self.field.render_view(value='Audio content'))
self.field.values['audio_preload'] = False
......@@ -55,7 +55,7 @@ class TestAudioField(ERP5TypeTestCase):
self.field.values['audio_error_message'] = 'Another error message'
self.assertEqual('<audio src="Another Audio content" ' +
'loop="loop" autoplay="autoplay" >\nAnother error ' +
'loop="loop" autoplay="autoplay" >Another error ' +
'message</audio>', self.field.render_view(value='Another Audio content'))
import unittest
......
......@@ -415,12 +415,12 @@ class TestTextAreaField(ERP5TypeTestCase):
def test_render_view(self):
self.field.values['default'] = 'My first Line\n&My Second Line\tfoo'
self.assertEqual('<div >\nMy first Line<br/><br/>&amp;My Second Line\tfoo</div>',
self.assertEqual('<div >My first Line<br/><br/>&amp;My Second Line\tfoo</div>',
self.field.render_view(value=['My first Line\n', '&My Second Line\tfoo']))
editable_mode = self.portal.REQUEST.get('editable_mode', 1)
self.portal.REQUEST.set('editable_mode', 0)
try:
self.assertEqual('<div >\nMy first Line<br/>&amp;My Second Line\tfoo</div>',
self.assertEqual('<div >My first Line<br/>&amp;My Second Line\tfoo</div>',
self.field.render(REQUEST=self.portal.REQUEST))
finally:
self.portal.REQUEST.set('editable_mode', editable_mode)
......@@ -452,7 +452,7 @@ class TestLinesField(ERP5TypeTestCase):
def test_render_view(self):
self.assertEqual(self.field.render_view(value=['My first Line\n', '&My Second Line\tfoo']),
'<div >\nMy first Line<br />\n<br />\n&amp;My Second Line\tfoo</div>')
'<div >My first Line<br />\n<br />\n&amp;My Second Line\tfoo</div>')
def test_render_odt(self):
self.field.values['default'] = ['A', 'B']
......
......@@ -43,7 +43,7 @@ class TestVideoField(ERP5TypeTestCase):
def test_render_view(self):
self.field.values['default'] = 'Video content'
self.assertEqual('<video preload="preload" src="Video content" controls="controls" height="85" width="160" >\nYour browser does not support video tag.</video>', \
self.assertEqual('<video preload="preload" src="Video content" controls="controls" height="85" width="160" >Your browser does not support video tag.</video>', \
self.field.render_view(value='Video content'))
self.field.values['video_preload'] = False
......@@ -56,7 +56,7 @@ class TestVideoField(ERP5TypeTestCase):
self.assertEqual('<video src="Another Video content" ' +
'height="800" width="1280" loop="loop" autoplay="autoplay" ' +
'>\nAnother error message</video>', \
'>Another error message</video>', \
self.field.render_view(value='Another Video content'))
import unittest
......
......@@ -1699,13 +1699,27 @@ def render_tag(tag, **kw):
attr_str = string.join(attr_list, " ")
return "<%s %s %s" % (tag, attr_str, extra)
VOID_ELEMENT_LIST = ('area', 'base', 'br', 'col', 'embed', 'hr', 'img',
'input', 'link', 'meta', 'param', 'source', 'track',
'wbr')
def render_element(tag, **kw):
if kw.has_key('contents'):
contents = kw['contents']
del kw['contents']
return "%s>\n%s</%s>" % (apply(render_tag, (tag, ), kw), contents, tag)
else:
# https://www.w3.org/TR/html5/syntax.html#start-tags
# End tags are forbidden on void HTML elements
if tag in VOID_ELEMENT_LIST:
if kw.has_key('contents'):
raise ValueError('Void element %s does not accept content' % tag)
return apply(render_tag, (tag, ), kw) + " />"
else:
if kw.has_key('contents'):
contents = kw['contents']
del kw['contents']
if tag == 'textarea':
# Newlines at the start of textarea elements are ignored as an authoring convenience
# https://www.w3.org/TR/html52/syntax.html#the-in-body-insertion-mode
contents = '\n%s' % contents
else:
contents = ''
return "%s>%s</%s>" % (apply(render_tag, (tag, ), kw), contents, tag)
##############################################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment