From d5ed0163f25d0bb42c33b612021154daae9396af Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Wed, 13 Feb 2019 11:44:06 +0100 Subject: [PATCH] Fix CommentStoreComment RawMessage construction MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- includes/CommentStoreComment.php | 2 +- .../includes/CommentStoreCommentTest.php | 26 +++++++++++++++++++ tests/phpunit/includes/CommentStoreTest.php | 24 +++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/phpunit/includes/CommentStoreCommentTest.php diff --git a/includes/CommentStoreComment.php b/includes/CommentStoreComment.php index af866cdce7..9f1681dff0 100644 --- a/includes/CommentStoreComment.php +++ b/includes/CommentStoreComment.php @@ -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; } diff --git a/tests/phpunit/includes/CommentStoreCommentTest.php b/tests/phpunit/includes/CommentStoreCommentTest.php new file mode 100644 index 0000000000..2dfe03ad6b --- /dev/null +++ b/tests/phpunit/includes/CommentStoreCommentTest.php @@ -0,0 +1,26 @@ +assertSame( $message, $comment->message ); + } + + public function testConstructorWithoutMessage() { + $text = '{{template|param}}'; + $comment = new CommentStoreComment( null, $text ); + + $this->assertSame( $text, $comment->message->text() ); + } + +} diff --git a/tests/phpunit/includes/CommentStoreTest.php b/tests/phpunit/includes/CommentStoreTest.php index 78c5bf3a95..736104762c 100644 --- a/tests/phpunit/includes/CommentStoreTest.php +++ b/tests/phpunit/includes/CommentStoreTest.php @@ -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 ], ] -- 2.20.1