summaryrefslogtreecommitdiff
path: root/tko
diff options
context:
space:
mode:
Diffstat (limited to 'tko')
-rw-r--r--tko/jsonp_fetcher.cgi9
1 files changed, 6 insertions, 3 deletions
diff --git a/tko/jsonp_fetcher.cgi b/tko/jsonp_fetcher.cgi
index ef8e0a02..981c61cc 100644
--- a/tko/jsonp_fetcher.cgi
+++ b/tko/jsonp_fetcher.cgi
@@ -14,10 +14,13 @@ callback = form['callback'].value
try:
file_contents = urllib2.urlopen('http://localhost' + path).read()
+ # escape backslashes, double-quotes, newlines, and carriage returns -- all
+ # would mess up a Javascript string literal
escaped_contents = file_contents.replace(
- '\\', '\\\\').replace( # get rid of backslashes
- '"', r'\"').replace( # escape quotes
- '\n', '\\n') # escape newlines
+ '\\', r'\\').replace(
+ '"', r'\"').replace(
+ '\n', r'\n').replace(
+ '\r', r'\r')
result = '{"contents" : "%s"}' % escaped_contents
except urllib2.HTTPError:
result = '{"error" : "File not found"}'