diff --git a/isso/views/comment.py b/isso/views/comment.py index f1a2b8b..1693cc5 100644 --- a/isso/views/comment.py +++ b/isso/views/comment.py @@ -95,8 +95,7 @@ def new(app, environ, request, uri): resp = Response(json.dumps(rv), 202 if rv["mode"] == 2 else 201, content_type='application/json') - resp.set_cookie(str(rv["id"]), app.sign([rv["id"], checksum]), - max_age=app.MAX_AGE, path='/') + resp.set_cookie(str(rv["id"]), app.sign([rv["id"], checksum]), max_age=app.MAX_AGE) return resp @@ -153,8 +152,12 @@ def single(app, environ, request, id): for key in set(rv.keys()) - FIELDS: rv.pop(key) + checksum = hashlib.md5(rv["text"]).hexdigest() rv["text"] = app.markdown(rv["text"]) - return Response(json.dumps(rv), 200, content_type='application/json') + + resp = Response(json.dumps(rv), 200, content_type='application/json') + resp.set_cookie(str(rv["id"]), app.sign([rv["id"], checksum]), max_age=app.MAX_AGE) + return resp if request.method == 'DELETE': diff --git a/specs/test_comment.py b/specs/test_comment.py index bb4ccac..a613028 100644 --- a/specs/test_comment.py +++ b/specs/test_comment.py @@ -236,3 +236,12 @@ class TestComments(unittest.TestCase): rv = self.get('/count?uri=%2Fpath%2F') assert rv.status_code == 404 + + def testModify(self): + self.post('/new?uri=test', data=json.dumps({"text": "Tpyo"})) + + self.put('/id/1', data=json.dumps({"text": "Tyop"})) + assert json.loads(self.get('/id/1').data)["text"] == "
Tyop
\n" + + self.put('/id/1', data=json.dumps({"text": "Typo"})) + assert json.loads(self.get('/id/1').data)["text"] == "Typo
\n"