From 0363febeb2c6990e0d06c2f0772ca4f8370228aa Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 8 Apr 2018 08:12:07 -0700 Subject: [PATCH] Disable default syntax highlighting for large files in DocumentEngine Summary: Ref T13105. See also T7895. When users render very large files as source via DocumentEngine, skip highlighting. Test Plan: Fiddled with the limit, viewed files, saw highlighting degrade. Reviewers: mydeveloperday Reviewed By: mydeveloperday Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19306 --- .../PhabricatorSourceDocumentEngine.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/applications/files/document/PhabricatorSourceDocumentEngine.php b/src/applications/files/document/PhabricatorSourceDocumentEngine.php index cd7c2af92b..5a4b7f0be7 100644 --- a/src/applications/files/document/PhabricatorSourceDocumentEngine.php +++ b/src/applications/files/document/PhabricatorSourceDocumentEngine.php @@ -24,18 +24,31 @@ final class PhabricatorSourceDocumentEngine protected function newDocumentContent(PhabricatorDocumentRef $ref) { $content = $this->loadTextData($ref); + $messages = array(); + $highlighting = $this->getHighlightingConfiguration(); if ($highlighting !== null) { $content = PhabricatorSyntaxHighlighter::highlightWithLanguage( $highlighting, $content); } else { - $content = PhabricatorSyntaxHighlighter::highlightWithFilename( - $ref->getName(), - $content); + $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; + if (strlen($content) > $highlight_limit) { + $messages[] = $this->newMessage( + pht( + 'This file is larger than %s, so syntax highlighting was skipped.', + phutil_format_bytes($highlight_limit))); + } else { + $content = PhabricatorSyntaxHighlighter::highlightWithFilename( + $ref->getName(), + $content); + } } - return $this->newTextDocumentContent($content); + return array( + $messages, + $this->newTextDocumentContent($content), + ); } }