Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15304276
D14273.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D14273.diff
View Options
diff --git a/src/markup/syntax/highlighter/PhutilPygmentsSyntaxHighlighter.php b/src/markup/syntax/highlighter/PhutilPygmentsSyntaxHighlighter.php
--- a/src/markup/syntax/highlighter/PhutilPygmentsSyntaxHighlighter.php
+++ b/src/markup/syntax/highlighter/PhutilPygmentsSyntaxHighlighter.php
@@ -2,6 +2,9 @@
final class PhutilPygmentsSyntaxHighlighter extends Phobject {
+ const MAX_LINE_LENGTH = 10240;
+ const MAX_SOURCE_LENGTH = 1048576;
+
private $config = array();
public function setConfig($key, $value) {
@@ -17,6 +20,12 @@
// use it on files with "\r" newlines. If we have "\r" not followed by
// "\n" in the file, skip highlighting.
$language = null;
+ } else if ((strlen($source) > self::MAX_SOURCE_LENGTH) ||
+ ($this->getLongestLineLength($source) > self::MAX_LINE_LENGTH)) {
+ // `pygmentize` is really slow and expensive when dealing with long
+ // source but especially with long lines. Better skip highlighting than
+ // 500 error.
+ $language = null;
}
if ($language) {
@@ -40,6 +49,17 @@
->getHighlightFuture($source);
}
+ private function getLongestLineLength($source) {
+ $longest = 0;
+ $offset = 0;
+ while (($pos = strpos($source, "\n", $offset)) !== false) {
+ $longest = max($longest, $pos - $offset);
+ $offset = $pos + 1;
+ }
+ $longest = max($longest, strlen($source) - $offset);
+ return $longest;
+ }
+
private function getPygmentsLexerNameFromLanguageName($language) {
static $map = array(
'adb' => 'ada',
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 7, 1:33 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7312755
Default Alt Text
D14273.diff (1 KB)
Attached To
Mode
D14273: Skip pygmentize for large source and too long lines
Attached
Detach File
Event Timeline
Log In to Comment