Merge "Produce HTML for invalid JSON"
This commit is contained in:
commit
81434f95f5
2 changed files with 17 additions and 3 deletions
|
|
@ -129,8 +129,14 @@ class JsonContentHandler extends CodeContentHandler {
|
|||
'@phan-var JsonContent $content';
|
||||
// FIXME: WikiPage::doUserEditContent generates parser output before validation.
|
||||
// As such, native data may be invalid (though output is discarded later in that case).
|
||||
if ( $cpoParams->getGenerateHtml() && $content->isValid() ) {
|
||||
$parserOutput->setText( $content->rootValueTable( $content->getData()->getValue() ) );
|
||||
if ( $cpoParams->getGenerateHtml() ) {
|
||||
if ( $content->isValid() ) {
|
||||
$parserOutput->setText( $content->rootValueTable( $content->getData()->getValue() ) );
|
||||
} else {
|
||||
$error = wfMessage( 'invalid-json-data' )->parse();
|
||||
$parserOutput->setText( $error );
|
||||
}
|
||||
|
||||
$parserOutput->addModuleStyles( [ 'mediawiki.content.json' ] );
|
||||
} else {
|
||||
$parserOutput->setText( null );
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ class JsonContentHandlerIntegrationTest extends MediaWikiLangTestCase {
|
|||
'<script>alert("evil!")</script>"' .
|
||||
'</td></tr></tbody></table>',
|
||||
],
|
||||
[
|
||||
'{ broken JSON ]',
|
||||
'Invalid JSON: $1',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +60,11 @@ class JsonContentHandlerIntegrationTest extends MediaWikiLangTestCase {
|
|||
* @covers JsonContentHandler::fillParserOutput
|
||||
*/
|
||||
public function testFillParserOutput( $data, $expected ) {
|
||||
$content = new JsonContent( FormatJson::encode( $data ) );
|
||||
if ( !is_string( $data ) ) {
|
||||
$data = FormatJson::encode( $data );
|
||||
}
|
||||
|
||||
$content = new JsonContent( $data );
|
||||
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
||||
$parserOutput = $contentRenderer->getParserOutput(
|
||||
$content,
|
||||
|
|
|
|||
Loading…
Reference in a new issue