From 02db978308fe8d478cdfa5f47a9fe91cd10a8f41 Mon Sep 17 00:00:00 2001 From: Laurent Arnoud Date: Wed, 4 Dec 2013 00:35:09 +0100 Subject: [PATCH] Add check with blank text --- isso/views/comments.py | 2 +- specs/test_comments.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/isso/views/comments.py b/isso/views/comments.py index 2583941..8ac290d 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -109,7 +109,7 @@ class API(object): if not isinstance(comment.get(key), (str, type(None))): return False, "%s must be a string or null" % key - if len(comment["text"]) < 3: + if len(comment["text"].rstrip()) < 3: return False, "text is too short (minimum length: 3)" if len(comment.get("email") or "") > 254: diff --git a/specs/test_comments.py b/specs/test_comments.py index 81d90a8..1985f0e 100644 --- a/specs/test_comments.py +++ b/specs/test_comments.py @@ -102,6 +102,12 @@ class TestComments(unittest.TestCase): rv = loads(r.data) assert len(rv) == 20 + def testCreateBlank(self): + rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': ''})) + assert rv.status_code == 400 + rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': "\n\n\n"})) + assert rv.status_code == 400 + def testGetInvalid(self): assert self.get('/?uri=%2Fpath%2F&id=123').status_code == 404