Fix CommentStoreComment RawMessage construction

If a CommentStoreComment is constructed without a Message argument, then
the RawMessage it uses instead should specify the comment text as a
plain-text parameter, not as a regular parameter: we don’t want any
syntax in the text to be interpreted at the Message level.

Change-Id: If14debde2bceae695c8955604ee96bd5005d8b66
This commit is contained in:
Lucas Werkmeister 2019-02-13 11:44:06 +01:00 committed by Brad Jorsch
parent 4091905d5b
commit d5ed0163f2
3 changed files with 40 additions and 12 deletions

View file

@ -50,7 +50,7 @@ class CommentStoreComment {
public function __construct( $id, $text, Message $message = null, array $data = null ) {
$this->id = $id;
$this->text = $text;
$this->message = $message ?: new RawMessage( '$1', [ $text ] );
$this->message = $message ?: new RawMessage( '$1', [ Message::plaintextParam( $text ) ] );
$this->data = $data;
}

View file

@ -0,0 +1,26 @@
<?php
use PHPUnit\Framework\TestCase;
/**
* @covers CommentStoreComment
*
* @license GPL-2.0-or-later
*/
class CommentStoreCommentTest extends TestCase {
public function testConstructorWithMessage() {
$message = new Message( 'test' );
$comment = new CommentStoreComment( null, 'test', $message );
$this->assertSame( $message, $comment->message );
}
public function testConstructorWithoutMessage() {
$text = '{{template|param}}';
$comment = new CommentStoreComment( null, $text );
$this->assertSame( $text, $comment->message->text() );
}
}

View file

@ -383,6 +383,8 @@ class CommentStoreTest extends MediaWikiLangTestCase {
"message keys $from" );
$this->assertEquals( $expect['message']->text(), $actual->message->text(),
"message rendering $from" );
$this->assertEquals( $expect['text'], $actual->message->text(),
"message rendering and text $from" );
$this->assertEquals( $expect['data'], $actual->data, "data $from" );
}
@ -400,7 +402,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
$expectOld = [
'text' => $expect['text'],
'message' => new RawMessage( '$1', [ $expect['text'] ] ),
'message' => new RawMessage( '$1', [ Message::plaintextParam( $expect['text'] ) ] ),
'data' => null,
];
@ -490,7 +492,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
$expectOld = [
'text' => $expect['text'],
'message' => new RawMessage( '$1', [ $expect['text'] ] ),
'message' => new RawMessage( '$1', [ Message::plaintextParam( $expect['text'] ) ] ),
'data' => null,
];
@ -568,7 +570,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
$db = wfGetDB( DB_REPLICA ); // for timestamps
$msgComment = new Message( 'parentheses', [ 'message comment' ] );
$textCommentMsg = new RawMessage( '$1', [ 'text comment' ] );
$textCommentMsg = new RawMessage( '$1', [ Message::plaintextParam( '{{text}} comment' ) ] );
$nestedMsgComment = new Message( [ 'parentheses', 'rawmessage' ], [ new Message( 'mainpage' ) ] );
$comStoreComment = new CommentStoreComment(
null, 'comment store comment', null, [ 'foo' => 'bar' ]
@ -576,15 +578,15 @@ class CommentStoreTest extends MediaWikiLangTestCase {
return [
'Simple table, text comment' => [
'commentstore1', 'cs1_comment', 'cs1_id', 'text comment', null, [
'text' => 'text comment',
'commentstore1', 'cs1_comment', 'cs1_id', '{{text}} comment', null, [
'text' => '{{text}} comment',
'message' => $textCommentMsg,
'data' => null,
]
],
'Simple table, text comment with data' => [
'commentstore1', 'cs1_comment', 'cs1_id', 'text comment', [ 'message' => 42 ], [
'text' => 'text comment',
'commentstore1', 'cs1_comment', 'cs1_id', '{{text}} comment', [ 'message' => 42 ], [
'text' => '{{text}} comment',
'message' => $textCommentMsg,
'data' => [ 'message' => 42 ],
]
@ -619,15 +621,15 @@ class CommentStoreTest extends MediaWikiLangTestCase {
],
'Revision, text comment' => [
'commentstore2', 'cs2_comment', 'cs2_id', 'text comment', null, [
'text' => 'text comment',
'commentstore2', 'cs2_comment', 'cs2_id', '{{text}} comment', null, [
'text' => '{{text}} comment',
'message' => $textCommentMsg,
'data' => null,
]
],
'Revision, text comment with data' => [
'commentstore2', 'cs2_comment', 'cs2_id', 'text comment', [ 'message' => 42 ], [
'text' => 'text comment',
'commentstore2', 'cs2_comment', 'cs2_id', '{{text}} comment', [ 'message' => 42 ], [
'text' => '{{text}} comment',
'message' => $textCommentMsg,
'data' => [ 'message' => 42 ],
]