From 971e14ea4b454df71f142f18738e33848b205ad4 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 22 Mar 2017 16:34:53 +0100 Subject: 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 --- application/controllers/file/file_default.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'application') 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'))) -- cgit v1.2.3-24-g4f1b