diff options
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/app.py | 4 | ||||
-rw-r--r-- | libpathod/utils.py | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/libpathod/app.py b/libpathod/app.py index b8e1ccdd..c94e61ca 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -1,6 +1,6 @@ import logging, pprint, cStringIO from flask import Flask, jsonify, render_template, request, abort -import version, rparse +import version, rparse, utils logging.basicConfig(level="DEBUG") app = Flask(__name__) @@ -83,5 +83,5 @@ def preview(): s = cStringIO.StringIO() r.serve(s, check=app.config["pathod"].check_size) - args["output"] = s.getvalue() + args["output"] = utils.escape_unprintables(s.getvalue()) return render_template("preview.html", **args) diff --git a/libpathod/utils.py b/libpathod/utils.py index 311d8f77..40f37cab 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -41,6 +41,15 @@ def parse_anchor_spec(s): return tuple(s.split("=", 1)) +def escape_unprintables(s): + s = s.replace("\r\n", "PATHOD_MARKER_RN") + s = s.replace("\n", "PATHOD_MARKER_N") + s = repr(s)[1:-1] + s = s.replace("PATHOD_MARKER_RN", "\n") + s = s.replace("PATHOD_MARKER_N", "\n") + return s + + class Data: def __init__(self, name): m = __import__(name) |