From 7d90eb65edf58815296f41931dba38d3051a41d7 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 8 Apr 2012 14:40:59 +1200 Subject: [PATCH] Catch all errors when using jsbeautifier. Turns out there are some problems that can raise arbitrary exceptions. --- libmproxy/console/contentview.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 97d217f28..c4e5d9ac8 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -232,7 +232,11 @@ def view_urlencoded(hdrs, content): def view_javascript(hdrs, content): opts = jsbeautifier.default_options() opts.indent_size = 2 - res = jsbeautifier.beautify(content[:VIEW_CUTOFF], opts) + try: + res = jsbeautifier.beautify(content[:VIEW_CUTOFF], opts) + except: + # Bugs in jsbeautifier mean that it can trhow arbitrary errors. + return None return "JavaScript", _view_text(res, len(content))