Skip to content

Commit

Permalink
add check for some invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Feb 14, 2012
1 parent a41c357 commit 9d7a0da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clj.py
Expand Up @@ -98,7 +98,11 @@ def __read_token(self):
## skip all stop chars if necessary
while c in self.stop_chars:
c = fd.read(1)


## raise exception when unexpected EOF found
if c == '':
raise ValueError("Unexpected EOF")

t, coll = self.__get_type_from_char(c)
if coll:
## move cursor
Expand Down
4 changes: 4 additions & 0 deletions tests/clj-test.py
Expand Up @@ -48,6 +48,10 @@ def test_all_data(self):
for k,v in self.data.items():
self.assertEqual(k, clj.dumps(v))

def test_misformed_data(self):
data = "[1 2 3"
self.assertRaises(ValueError, clj.loads, data)


if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit 9d7a0da

Please sign in to comment.