Merge "rest: Return a 400 for invalid render IDs" into REL1_43
This commit is contained in:
commit
637e4121dc
4 changed files with 24 additions and 1 deletions
|
|
@ -368,7 +368,14 @@ class HtmlInputTransformHelper {
|
|||
throw new LocalizedHttpException( new MessageValue( "rest-bad-etag", [ $key ] ), 400 );
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$originalRendering = ParsoidRenderID::newFromKey( $key );
|
||||
} catch ( InvalidArgumentException $e ) {
|
||||
throw new LocalizedHttpException(
|
||||
new MessageValue( 'rest-parsoid-bad-render-id', [ $key ] ),
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif ( !empty( $original['html'] ) || !empty( $original['data-parsoid'] ) ) {
|
||||
// NOTE: We might have an incomplete PageBundle here, with no HTML but with data-parsoid!
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
"rest-unsupported-target-format": "The requested target format is not supported.",
|
||||
"rest-parsoid-resource-exceeded": "Resource limit exceeded",
|
||||
"rest-parsoid-error": "Parsoid error.",
|
||||
"rest-parsoid-bad-render-id": "Bad Parsoid render ID: $1",
|
||||
"rest-bad-stash-key": "Bad stash key.",
|
||||
"rest-html-key-expected": "Expected <var>html</var> key in body",
|
||||
"rest-invalid-transform": "Invalid transform: $1 to $2",
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
"rest-transform-missing-title": "Error message for REST API debugging, shown when no title or wikitext is provided",
|
||||
"rest-unsupported-target-format": "Error message for REST API debugging, shown when the requested target format is not supported",
|
||||
"rest-parsoid-resource-exceeded": "Error message for REST API debugging, shown when a resource limit is exceeded while converting between wikitext and HTML.",
|
||||
"rest-parsoid-bad-render-id": "Error message for REST API debugging, shown when a ParsoidRenderID object cannot be created from the provided key. Parameters:\n* $1: The key",
|
||||
"rest-parsoid-error": "Error message for REST API debugging, indicating an unspecified backend error occurred while converting between wikitext and HTML.\n\n[[:mw:Parsoid|Parsoid]] is the name of a software library; do not translate that name.",
|
||||
"rest-bad-stash-key": "Error message for REST API debugging, shown when When the rednerid or etag given in the request is not a valid stash key.",
|
||||
"rest-html-key-expected": "Error message for REST API debugging, shown when when the \"html\" key is missing from the request body",
|
||||
|
|
|
|||
|
|
@ -1188,6 +1188,20 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase {
|
|||
$helper->getContent();
|
||||
}
|
||||
|
||||
public function testHandlesInvalidRenderID(): void {
|
||||
$page = $this->getExistingTestPage( __METHOD__ );
|
||||
|
||||
$body = [ 'html' => 'hi', 'original' => [ 'renderid' => 'foo' ] ];
|
||||
$params = [];
|
||||
|
||||
$this->expectExceptionObject( new LocalizedHttpException(
|
||||
new MessageValue( 'rest-parsoid-bad-render-id', [ 'foo' ] ),
|
||||
400
|
||||
) );
|
||||
|
||||
$this->newHelper( [], StatsFactory::newNull(), $page, $body, $params );
|
||||
}
|
||||
|
||||
private function newHtmlToContentTransform( $html, $methodOverrides = [] ): HtmlToContentTransform {
|
||||
$transform = $this->getMockBuilder( HtmlToContentTransform::class )
|
||||
->onlyMethods( array_keys( $methodOverrides ) )
|
||||
|
|
|
|||
Loading…
Reference in a new issue