Changeset View
Changeset View
Standalone View
Standalone View
src/markup/syntax/highlighter/PhutilPygmentsSyntaxHighlighter.php
Show All 18 Lines | if (preg_match('/\r(?!\n)/', $source)) { | ||||
$language = null; | $language = null; | ||||
} | } | ||||
if ($language) { | if ($language) { | ||||
$language = $this->getPygmentsLexerNameFromLanguageName($language); | $language = $this->getPygmentsLexerNameFromLanguageName($language); | ||||
$future = new ExecFuture( | $future = new ExecFuture( | ||||
'pygmentize -O encoding=utf-8 -O stripnl=False -f html -l %s', | 'pygmentize -O encoding=utf-8 -O stripnl=False -f html -l %s', | ||||
$language); | $language); | ||||
$scrub = false; | $scrub = false; | ||||
if ($language == 'php' && strpos($source, '<?') === false) { | if ($language == 'php' && strpos($source, '<?') === false) { | ||||
$source = "<?php\n".$source; | $source = "<?php\n".$source; | ||||
$scrub = true; | $scrub = true; | ||||
} | } | ||||
// See T13224. In some cases, "pygmentize" has explosive runtime on small | |||||
// inputs. Put a hard cap on how long it is allowed to run for to limit | |||||
// the amount of damage it can do. | |||||
$future->setTimeout(15); | |||||
$future->write($source); | $future->write($source); | ||||
return new PhutilDefaultSyntaxHighlighterEnginePygmentsFuture( | return new PhutilDefaultSyntaxHighlighterEnginePygmentsFuture( | ||||
$future, | $future, | ||||
$source, | $source, | ||||
$scrub); | $scrub); | ||||
} | } | ||||
return id(new PhutilDefaultSyntaxHighlighter()) | return id(new PhutilDefaultSyntaxHighlighter()) | ||||
->getHighlightFuture($source); | ->getHighlightFuture($source); | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |