Skip to content

Commit

Permalink
String: raise Invalid on deserialization from a non-string (fixes #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Lamut committed Aug 16, 2013
1 parent b46bde7 commit 30f002e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion colander/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def deserialize(self, node, cstruct):
else:
result = text_type(cstruct)
else:
result = text_type(cstruct)
raise Invalid(node)
except Exception as e:
raise Invalid(node,
_('${val} is not a string: ${err}',
Expand Down
11 changes: 9 additions & 2 deletions colander/tests/test_colander.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,11 +1329,11 @@ def test_deserialize_unicode_from_None(self):
self.assertEqual(result, uni)

def test_deserialize_nonunicode_from_None(self):
import colander
value = object()
node = DummySchemaNode(None)
typ = self._makeOne()
result = typ.deserialize(node, value)
self.assertEqual(result, text_type(value))
self.assertRaises(colander.Invalid, typ.deserialize, node, value)

def test_deserialize_from_utf8(self):
uni = text_(b'\xe3\x81\x82', encoding='utf-8')
Expand All @@ -1351,6 +1351,13 @@ def test_deserialize_from_utf16(self):
result = typ.deserialize(node, utf16)
self.assertEqual(result, uni)

def test_deserialize_from_nonstring_obj(self):
import colander
value = object()
node = DummySchemaNode(None)
typ = self._makeOne()
self.assertRaises(colander.Invalid, typ.deserialize, node, value)

def test_serialize_null(self):
from colander import null
node = DummySchemaNode(None)
Expand Down

0 comments on commit 30f002e

Please sign in to comment.