Skip to content
Browse files

add check for some invalid data

  • Loading branch information...
1 parent a41c357 commit 9d7a0da1df82ed41b4cc5cf0ad803c8cb441654a @sunng87 committed Feb 14, 2012
Showing with 9 additions and 1 deletion.
  1. +5 −1 clj.py
  2. +4 −0 tests/clj-test.py
View
6 clj.py
@@ -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
View
4 tests/clj-test.py
@@ -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()

0 comments on commit 9d7a0da

Please sign in to comment.
Something went wrong with that request. Please try again.