HTMLStringToElements adds comments to force tag closers

This commit is contained in:
Darren Ranalli 2009-11-21 01:18:25 +00:00
parent deaa391103
commit ac091ce40e
2 changed files with 12 additions and 2 deletions

View File

@ -31,8 +31,7 @@ def displayhtml (public_key,
else:
server = API_SERVER
# DCR: added comment to force ElementTree to emit </script> tag closer
return """<script type="text/javascript" src="%(ApiServer)s/challenge?k=%(PublicKey)s%(ErrorParam)s"><!-- --></script>
return """<script type="text/javascript" src="%(ApiServer)s/challenge?k=%(PublicKey)s%(ErrorParam)s"></script>
<noscript>
<iframe src="%(ApiServer)s/noscript?k=%(PublicKey)s%(ErrorParam)s" height="300" width="500" frameborder="0"></iframe><br />

View File

@ -4083,6 +4083,17 @@ class HTMLStringToElements(HTMLParser):
self._elementStack.top().text = data
def handle_endtag(self, tag):
top = self._elementStack.top()
if len(top.getchildren()) == 0:
# insert a comment to prevent ElementTree from using <... /> convention
# force it to create a tag closer a la </tag>
# prevents problems in certain browsers
if top.tag == 'script' and top.get('type') == 'text/javascript':
if top.text == None:
top.text = '// force tag closer'
else:
self.handle_comment('force tag closer')
self._elementStack.pop()
self._elementStack.pop()
def handle_comment(self, data):