Fix the case of empty <syntaxhighlight /> tags

Bug: T315740
Change-Id: I685806d4e8992a54f17d29a9187807bb30e31ef8
This commit is contained in:
Sébastien Beyou 2022-08-21 13:46:17 +02:00
parent 05bc73fd1f
commit b08c0a7cb9
2 changed files with 13 additions and 3 deletions

View file

@ -109,7 +109,7 @@ class SyntaxHighlight extends ExtensionTagHandler {
/**
* Parser hook for <source> to add deprecated tracking category
*
* @param string $text
* @param ?string $text
* @param array $args
* @param Parser $parser
* @return string
@ -162,7 +162,7 @@ class SyntaxHighlight extends ExtensionTagHandler {
/**
* Parser hook for both <source> and <syntaxhighlight> logic
*
* @param string $text
* @param ?string $text
* @param array $args
* @param Parser $parser
* @return string
@ -170,7 +170,7 @@ class SyntaxHighlight extends ExtensionTagHandler {
*/
public static function parserHook( $text, $args, $parser ) {
// Replace strip markers (For e.g. {{#tag:syntaxhighlight|<nowiki>...}})
$out = $parser->getStripState()->unstripNoWiki( $text );
$out = $parser->getStripState()->unstripNoWiki( $text ?? '' );
$result = self::processContent( $out, $args, $parser );
foreach ( $result['cats'] as $cat ) {

View file

@ -169,6 +169,16 @@ Enclose with nowiki
<p><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr" about="#mwt1" typeof="mw:Extension/syntaxhighlight mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#tag:syntaxhighlight","function":"tag"},"params":{"1":{"wt":"&lt;nowiki>foo&lt;/nowiki>"},"lang":{"wt":"\"text\""},"inline":{"wt":"none"}},"i":0}}]}'>foo</code></p>
!! end
!! test
Self-closing tag
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
<syntaxhighlight lang="CSharp" />
!! html
<div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"></div>
!! end
!! test
No code
!! options