summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-03-22 16:34:53 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-03-22 16:34:53 +0100
commit971e14ea4b454df71f142f18738e33848b205ad4 (patch)
tree30c811aaa79bcce4fe23394150baa56de86cd256 /application
parent06ce8d971b1dfd7a520c1c2e4933d84f3e4c80d0 (diff)
Reformat single-line JSON when rendering
Be conservative and only apply the reformating for single line pastes. This should cover the most common cases and protect against trying to reformat non-json content. Fixes #14 Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/file/file_default.php5
1 files changed, 5 insertions, 0 deletions
diff --git a/application/controllers/file/file_default.php b/application/controllers/file/file_default.php
index 28d83282e..15fb54832 100644
--- a/application/controllers/file/file_default.php
+++ b/application/controllers/file/file_default.php
@@ -252,6 +252,11 @@ class File_default extends MY_Controller {
$content = file_get_contents($file);
+ $linecount = count(explode("\n", $content));
+ if ($lexer === "json" && $linecount === 1) {
+ $content = json_encode(json_decode($content), JSON_PRETTY_PRINT);
+ }
+
if ($lexer == "ascii") {
// TODO: use exec safe and catch exception
$ret = (new \libraries\ProcRunner(array('ansi2html', '-p')))