mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SyntaxHighlight_GeSHi
synced 2024-11-24 06:24:29 +00:00
Fix "MWException: Unexpected output from Pygments" in highlight fallback
Follows-up 043969f84e
.
This caused a fatal MWException when saving/reading pages that contain a
<source> that couldn't be highlighted (e.g. no lang attribute, unknown
lang, or too large).
Specifically when wgWellFormedXml=false, in which case $out isn't
just from Pygments, but actually from our own Html::element.
Change-Id: Ib299a274d28021b2c7bba52d763dd1e17c1f09ec
This commit is contained in:
parent
509a23af6b
commit
206f0fd585
|
@ -158,8 +158,9 @@ class SyntaxHighlight_GeSHi {
|
|||
|
||||
// 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 = array();
|
||||
if ( preg_match( '/^<div class="mw-highlight">(.*)<\/div>$/s', trim( $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' );
|
||||
|
|
|
@ -13,6 +13,30 @@ foobar
|
|||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
No language specified
|
||||
!! wikitext
|
||||
<source>
|
||||
foo
|
||||
</source>
|
||||
!! html
|
||||
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre>foo</pre></div>
|
||||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
No language specified (no wellformed xml)
|
||||
!! config
|
||||
wgWellFormedXml=false
|
||||
!! wikitext
|
||||
<source>
|
||||
bar
|
||||
</source>
|
||||
!! html
|
||||
<div class="mw-highlight mw-content-ltr" dir=ltr><pre>bar</pre></div>
|
||||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
XSS is escaped
|
||||
!!input
|
||||
|
|
Loading…
Reference in a new issue