Browse Source

HTMLStringToElements adds comments to force tag closers

Darren Ranalli 16 years ago
parent
commit
ac091ce40e
2 changed files with 12 additions and 2 deletions
  1. 1 2
      direct/src/http/recaptcha.py
  2. 11 0
      direct/src/showbase/PythonUtil.py

+ 1 - 2
direct/src/http/recaptcha.py

@@ -31,8 +31,7 @@ def displayhtml (public_key,
     else:
     else:
         server = API_SERVER
         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>
 <noscript>
   <iframe src="%(ApiServer)s/noscript?k=%(PublicKey)s%(ErrorParam)s" height="300" width="500" frameborder="0"></iframe><br />
   <iframe src="%(ApiServer)s/noscript?k=%(PublicKey)s%(ErrorParam)s" height="300" width="500" frameborder="0"></iframe><br />

+ 11 - 0
direct/src/showbase/PythonUtil.py

@@ -4083,6 +4083,17 @@ class HTMLStringToElements(HTMLParser):
             self._elementStack.top().text = data
             self._elementStack.top().text = data
 
 
     def handle_endtag(self, tag):
     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()
         self._elementStack.pop()
 
 
     def handle_comment(self, data):
     def handle_comment(self, data):