If there is no input, don't try and shell out to pygments

pygments will just wait for stdin if the stdin that was passed
to it was empty.

Bug: T188019
Change-Id: I46271f31df74822bc71b3ac283fa572f2d149d67
This commit is contained in:
Kunal Mehta 2018-02-22 13:19:53 -08:00
parent 3a588ed5da
commit cda15b184c
2 changed files with 28 additions and 5 deletions

View file

@ -152,11 +152,13 @@ class SyntaxHighlight {
// Unwrap Pygments output to provide our own wrapper. We can't just always use the 'nowrap'
// option (pass 'inline'), since it disables other useful things like line highlighting.
// Tolerate absence of quotes for Html::element() and wgWellFormedXml=false.
$m = [];
if ( preg_match( '/^<div class="?mw-highlight"?>(.*)<\/div>$/s', trim( $out ), $m ) ) {
$out = trim( $m[1] );
} else {
throw new MWException( 'Unexpected output from Pygments encountered' );
if ( $out !== '' ) {
$m = [];
if ( preg_match( '/^<div class="?mw-highlight"?>(.*)<\/div>$/s', trim( $out ), $m ) ) {
$out = trim( $m[1] );
} else {
throw new MWException( 'Unexpected output from Pygments encountered' );
}
}
// Use 'nowiki' strip marker to prevent list processing (also known as doBlockLevels()).
@ -218,6 +220,9 @@ class SyntaxHighlight {
$status->warning( 'syntaxhighlight-error-exceeds-size-limit',
$length, self::HIGHLIGHT_MAX_BYTES );
$lexer = null;
} elseif ( $length === 0 ) {
$status->value = '';
return $status;
}
if ( Shell::isDisabled() ) {

View file

@ -162,3 +162,21 @@ Enclose with nowiki
<p><code class="mw-highlight" dir="ltr">foo</code>
</p>
!! end
!! test
No code
!! input
<source lang="CSharp"></source>
!! result
<div class="mw-highlight mw-content-ltr" dir="ltr"></div>
!! end
!! test
Just whitespace
!! input
<source lang="CSharp"> </source>
!! result
<div class="mw-highlight mw-content-ltr" dir="ltr"></div>
!! end