From 6c565e778f986055f0edd2a170e005f4adb45a5d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 24 Jul 2012 22:38:48 +1200 Subject: [PATCH] Make previews safer by stripping pauses. --- libpathod/app.py | 1 + libpathod/rparse.py | 6 ++++++ test/test_rparse.py | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/libpathod/app.py b/libpathod/app.py index 5de69337b..111fafe50 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -90,6 +90,7 @@ def preview(): return render("preview.html", **args) s = cStringIO.StringIO() + r.preview_safe() r.serve(s, check=app.config["pathod"].check_size) args["output"] = utils.escape_unprintables(s.getvalue()) return render("preview.html", **args) diff --git a/libpathod/rparse.py b/libpathod/rparse.py index e56135ea4..d60a78d39 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -527,6 +527,12 @@ class Message: l += len(self.body) return l + def preview_safe(self): + """ + Modify this message to be safe for previews. + """ + self.actions = [i for i in self.actions if i[1] != "pause"] + def effective_length(self, actions): """ Calculate the length of the base message with all applied actions. diff --git a/test/test_rparse.py b/test/test_rparse.py index 922c8fc61..dadf5bc1a 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -493,6 +493,12 @@ class TestResponse: r.actions = actions testlen(r, actions) + def test_render(self): + r = rparse.parse_response({}, "400:p0,100:dr") + assert r.actions[0][1] == "pause" + r.preview_safe() + assert not r.actions[0][1] == "pause" + def test_read_file():