=== modified file 'django/newforms/forms.py'
--- django/newforms/forms.py	2008-07-07 20:27:42 +0000
+++ django/newforms/forms.py	2008-07-08 07:33:45 +0000
@@ -5,7 +5,7 @@
 from copy import deepcopy
 
 from django.utils.datastructures import SortedDict
-from django.utils.html import escape
+from django.utils.html import escape, conditional_escape
 from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
 from django.utils.safestring import mark_safe
 
@@ -127,7 +127,7 @@
         output, hidden_fields = [], []
         for name, field in self.fields.items():
             bf = BoundField(self, field, name)
-            bf_errors = self.error_class([escape(error) for error in bf.errors]) # Escape and cache in local variable.
+            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
             if bf.is_hidden:
                 if bf_errors:
                     top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])

=== modified file 'django/newforms/util.py'
--- django/newforms/util.py	2008-04-27 08:31:41 +0000
+++ django/newforms/util.py	2008-03-14 13:28:12 +0000
@@ -1,6 +1,5 @@
-from django.utils.html import escape
+from django.utils.html import conditional_escape
 from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode
-from django.utils.functional import Promise
 from django.utils.safestring import mark_safe
 
 def flatatt(attrs):
@@ -10,7 +9,7 @@
     XML-style pairs.  It is assumed that the keys do not need to be XML-escaped.
     If the passed dictionary is empty, then return an empty string.
     """
-    return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
+    return mark_safe(u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k, v in attrs.items()]))
 
 class ErrorDict(dict, StrAndUnicode):
     """
@@ -56,9 +55,9 @@
         a string) or a list of objects.
         """
         if isinstance(message, list):
-            self.messages = ErrorList([smart_unicode(msg) for msg in message])
+            self.messages = ErrorList([conditional_escape(smart_unicode(msg)) for msg in message])
         else:
-            message = smart_unicode(message)
+            message = conditional_escape(smart_unicode(message))
             self.messages = ErrorList([message])
 
     def __str__(self):

=== modified file 'tests/regressiontests/forms/localflavor/ch.py'
--- tests/regressiontests/forms/localflavor/ch.py	2007-11-13 02:22:36 +0000
+++ tests/regressiontests/forms/localflavor/ch.py	2008-03-14 13:29:37 +0000
@@ -41,13 +41,13 @@
 >>> f.clean('C1234567<1')
 Traceback (most recent call last):
 ...
-ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.']
+ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567&lt;0 or 1234567890 format.']
 >>> f.clean('2123456700')
 u'2123456700'
 >>> f.clean('2123456701')
 Traceback (most recent call last):
 ...
-ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.']
+ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567&lt;0 or 1234567890 format.']
 
 # CHStateSelect #############################################################
 

=== modified file 'tests/regressiontests/forms/util.py'
--- tests/regressiontests/forms/util.py	2008-03-14 13:54:53 +0000
+++ tests/regressiontests/forms/util.py	2008-03-14 13:39:53 +0000
@@ -7,6 +7,11 @@
 >>> from django.newforms.util import *
 >>> from django.utils.translation import ugettext_lazy
 
+# Escaping.
+>>> from django.utils.html import escape
+>>> from django.utils.html import conditional_escape
+>>> script = "$('#example').html('<a href=\"http://www.example.com/\">example</a>');"
+
 ###########
 # flatatt #
 ###########
@@ -19,6 +24,22 @@
 >>> flatatt({})
 u''
 
+# Escaping.
+
+>>> flatatt({'onclick': script})
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+>>> flatatt({'onclick': escape(script)})
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+>>> flatatt({'onclick': conditional_escape(script)})
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+
+>>> conditional_escape(flatatt({'onclick': script}))
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+>>> conditional_escape(flatatt({'onclick': escape(script)}))
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+>>> conditional_escape(flatatt({'onclick': conditional_escape(script)}))
+u' onclick="$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);"'
+
 ###################
 # ValidationError #
 ###################
@@ -49,4 +70,33 @@
 # Can take a non-string.
 >>> print ValidationError(VeryBadError()).messages
 <ul class="errorlist"><li>A very bad error.</li></ul>
+
+# Escaping.
+
+>>> print ValidationError(script).messages
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print ValidationError(escape(script)).messages
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print ValidationError(conditional_escape(script)).messages
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print ErrorDict({'example': ValidationError(script).messages})
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+>>> print ErrorDict({'example': ValidationError(escape(script)).messages})
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+>>> print ErrorDict({'example': ValidationError(conditional_escape(script)).messages})
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+
+>>> print conditional_escape(unicode(ValidationError(script).messages))
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print conditional_escape(unicode(ValidationError(escape(script)).messages))
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print conditional_escape(unicode(ValidationError(conditional_escape(script)).messages))
+<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul>
+>>> print conditional_escape(unicode(ErrorDict({'example': ValidationError(script).messages})))
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+>>> print conditional_escape(unicode(ErrorDict({'example': ValidationError(escape(script)).messages})))
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+>>> print conditional_escape(unicode(ErrorDict({'example': ValidationError(conditional_escape(script)).messages})))
+<ul class="errorlist"><li>example<ul class="errorlist"><li>$(&#39;#example&#39;).html(&#39;&lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;&#39;);</li></ul></li></ul>
+
 """

