The previous implementation was using an ad-hoc regular expression which
was matching inside the data-mw attribute of Parsoid output, eg:
<sup about="#mwt42" [...] typeof="mw:Extension/ref mw:Error" data-mw="{"name":"ref","attrs":{"name":"infobox_stats_ref_rail"},"body":{"html":"<style data-mw-deduplicate=\"TemplateStyles:r1133582631\" typeof=\"...">
After substitution, the <link> element inserted contained " instead of
" and so broke out of the attribute.
Instead use a proper HTML tokenizer (via wikimedia/remex-html) so that
we don't allow bogus matches inside attribute values.
To fix up tests:
* Don't deduplicate styles when parsing UX messages (also helps performance)
* Don't deduplicate styles in ContentHandler integration tests
* Don't deduplicate styles by default in parser tests
(unless explicit option is set)
Depends-On: Id9801a9ff540bd818a32bc6fa35c48a9cff12d3a
Depends-On: I5111f1fdb7140948b82113adbc774af286174ab3
Followup-To: Ic0b17e361bf6eb0e71c498abc17f5f67f82318f8
Change-Id: I32d3d1772243c3819e1e1486351d16871b6e21c4
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
* @group Database
|
|
* ^--- needed, because we do need the database to test link updates
|
|
*/
|
|
class TextContentHandlerIntegrationTest extends MediaWikiLangTestCase {
|
|
|
|
public static function provideGetParserOutput() {
|
|
yield 'Basic render' => [
|
|
'title' => 'TextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_TEXT,
|
|
'text' => "hello ''world'' & [[stuff]]\n",
|
|
'expectedHtml' => "<pre>hello ''world'' & [[stuff]]\n</pre>",
|
|
'expectedFields' => [ 'Links' => [] ]
|
|
];
|
|
yield 'Multi line render' => [
|
|
'title' => 'TextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_TEXT,
|
|
'text' => "Test 1\nTest 2\n\nTest 3\n",
|
|
'expectedHtml' => "<pre>Test 1\nTest 2\n\nTest 3\n</pre>",
|
|
'expectedFields' => [ 'Links' => [] ]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideGetParserOutput
|
|
* @covers TextContentHandler::fillParserOutput
|
|
*/
|
|
public function testGetParserOutput( $title, $model, $text, $expectedHtml,
|
|
$expectedFields = null, $parserOptions = null
|
|
) {
|
|
$title = Title::newFromText( $title );
|
|
$content = ContentHandler::makeContent( $text, $title, $model );
|
|
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
|
$po = $contentRenderer->getParserOutput( $content, $title, null, $parserOptions );
|
|
|
|
$html = $po->getText( [
|
|
'deduplicateStyles' => false,
|
|
] );
|
|
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
|
|
|
|
if ( $expectedHtml !== null ) {
|
|
$this->assertEquals( $expectedHtml, trim( $html ) );
|
|
}
|
|
|
|
if ( $expectedFields ) {
|
|
foreach ( $expectedFields as $field => $exp ) {
|
|
$getter = 'get' . ucfirst( $field );
|
|
$v = $po->$getter();
|
|
|
|
if ( is_array( $exp ) ) {
|
|
$this->assertArrayEquals( $exp, $v );
|
|
} else {
|
|
$this->assertEquals( $exp, $v );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|