Skip to content

Commit

Permalink
fixed unicode issues in form.py (Bug#180653)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Jan 6, 2008
1 parent 4ab0b84 commit 3c82303
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/alltests.py
@@ -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()
16 changes: 16 additions & 0 deletions test/form.py
@@ -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()
4 changes: 2 additions & 2 deletions web/form.py
Expand Up @@ -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):
Expand Down

0 comments on commit 3c82303

Please sign in to comment.