Permalink
Browse files

fixed unicode issues in form.py (Bug#180653)

  • Loading branch information...
1 parent 4ab0b84 commit 3c82303b9c94e9ebeb0a05f46be8cca843d7cc21 @anandology anandology committed Jan 6, 2008
Showing with 20 additions and 4 deletions.
  1. +2 −2 test/alltests.py
  2. +16 −0 test/form.py
  3. +2 −2 web/form.py
View
@@ -1,8 +1,8 @@
import webtest
def suite():
- modules = ["doctests", "db"]
+ modules = ["doctests", "db", "form"]
return webtest.suite(modules)
if __name__ == "__main__":
- webtest.main()
+ webtest.main()
View
@@ -0,0 +1,16 @@
+import webtest
+from web import form
+
+class FormTest(webtest.TestCase):
+ def testUnicode(self):
+ t = form.Textbox('first_name', maxlength='255', description=u'\u1234', value=u'\u1234')
+ f = form.Form(t)
+ f.render() # this fails if unicode is not supported.
+
+ t = form.Textbox('first_name', maxlength='255', description=u'\u1234', value=u'\u1234')
+ t.note = u'\u1234'
+ f = form.Form(t)
+ f.render() # this fails if unicode is not supported.
+
+if __name__ == "__main__":
+ webtest.main()
View
@@ -29,14 +29,14 @@ def render(self):
out += self.rendernote(self.note)
out += '<table>\n'
for i in self.inputs:
- out += ' <tr><th><label for="%s">%s</label></th>' % (i.id, i.description)
+ out += ' <tr><th><label for="%s">%s</label></th>' % (i.id, net.websafe(i.description))
out += "<td>"+i.pre+i.render()+i.post+"</td>"
out += '<td id="note_%s">%s</td></tr>\n' % (i.id, self.rendernote(i.note))
out += "</table>"
return out
def rendernote(self, note):
- if note: return '<strong class="wrong">%s</strong>' % note
+ if note: return '<strong class="wrong">%s</strong>' % net.websafe(note)
else: return ""
def validates(self, source=None, _validate=True, **kw):

0 comments on commit 3c82303

Please sign in to comment.