[Checkins] SVN: Sandbox/malthe/chameleon.core/ Properly wrap validation strings.

Malthe Borch mborch at gmail.com
Thu Nov 13 11:11:13 EST 2008


Log message for revision 92906:
  Properly wrap validation strings.

Changed:
  U   Sandbox/malthe/chameleon.core/CHANGES.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py

-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-13 16:10:59 UTC (rev 92905)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-13 16:11:12 UTC (rev 92906)
@@ -4,6 +4,10 @@
 HEAD
 ~~~~
 
+- When validating inserted content (in debug-mode), make sure we wrap
+  content as a proper HTML document, including HTML entity
+  definitions. [malthe]
+
 - If an element does not belong to a known namespace, assume it's the
   default namespace. This change is relevant after the introduction of
   fallback elements. [malthe]

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py	2008-11-13 16:10:59 UTC (rev 92905)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py	2008-11-13 16:11:12 UTC (rev 92906)
@@ -21,8 +21,14 @@
     return ET
 
 def validate(string):
+    """Wraps string as a proper HTML document and validates it by
+    attempting to parse it using the active ElementTree parser."""
+    
+    validation_string = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ %s ]><div>%s</div>' % (
+        utils.entities, string)
+    
     try:
-        import_elementtree().fromstring("<div>%s</div>" % string)
+        import_elementtree().fromstring(validation_string)
     except xml.parsers.expat.ExpatError:
         raise ValidationError(string)
 



More information about the Checkins mailing list