Skip to content

Commit

Permalink
Make String serialize empty string to empty string instead of null
Browse files Browse the repository at this point in the history
This makes the following True:
``` String().serialize(node, u'') == u'' ```

Issue #72
  • Loading branch information
tranminhh committed Nov 16, 2012
1 parent e2ef91c commit ad04ea6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion colander/__init__.py
Expand Up @@ -982,7 +982,7 @@ def __init__(self, encoding=None):
self.encoding = encoding self.encoding = encoding


def serialize(self, node, appstruct): def serialize(self, node, appstruct):
if not appstruct: if appstruct in (null, None):
return null return null


try: try:
Expand Down
8 changes: 8 additions & 0 deletions colander/tests/test_colander.py
Expand Up @@ -1182,6 +1182,14 @@ def test_serialize_none(self):
result = typ.serialize(node, val) result = typ.serialize(node, val)
self.assertEqual(result, colander.null) self.assertEqual(result, colander.null)


def test_serialize_emptystring(self):
import colander
val = u''
node = DummySchemaNode(None)
typ = self._makeOne()
result = typ.serialize(node, val)
self.assertEqual(result, val)

def test_serialize_uncooperative(self): def test_serialize_uncooperative(self):
val = Uncooperative() val = Uncooperative()
node = DummySchemaNode(None) node = DummySchemaNode(None)
Expand Down

0 comments on commit ad04ea6

Please sign in to comment.