aboutsummaryrefslogtreecommitdiffstats
path: root/includes/CommentStore
diff options
context:
space:
mode:
authordaniel <dkinzler@wikimedia.org>2024-01-25 10:00:26 +0100
committerJforrester <jforrester@wikimedia.org>2024-01-25 15:02:05 +0000
commit6f1f783c7721a57ed1407231f75129822c07b5f8 (patch)
tree3224fe0dbc74208d9c3cad76723fb3a10b82ecd1 /includes/CommentStore
parent484d6106cbcc2a90ed8f2bfa7e5f4d2a00731adb (diff)
downloadmediawikicore-6f1f783c7721a57ed1407231f75129822c07b5f8.tar.gz
mediawikicore-6f1f783c7721a57ed1407231f75129822c07b5f8.zip
CommentStore: Force message to be a string
Apparently, we end with the comment text being null sometimes. That should not happen, and can lead to failures down the road. So we need to detect and prevent this case early. Bug: T355751 Change-Id: Ifc91416d297e9a569bc7a2981732e5dd808429aa
Diffstat (limited to 'includes/CommentStore')
-rw-r--r--includes/CommentStore/CommentStoreComment.php17
1 files changed, 14 insertions, 3 deletions
diff --git a/includes/CommentStore/CommentStoreComment.php b/includes/CommentStore/CommentStoreComment.php
index 255372047a36..d65e5f253d99 100644
--- a/includes/CommentStore/CommentStoreComment.php
+++ b/includes/CommentStore/CommentStoreComment.php
@@ -55,9 +55,20 @@ class CommentStoreComment {
* @param array|null $data
*/
public function __construct( $id, $text, Message $message = null, array $data = null ) {
- $this->id = $id;
- $this->text = $text;
- $this->message = $message ?: new RawMessage( '$1', [ Message::plaintextParam( $text ) ] );
+ if ( $text === null ) {
+ // TODO: Turn this warning into a proper type hint once we have
+ // found and fixed any offenders (T355751).
+ wfLogWarning( 'Comment text should not be null!' );
+ $text = '';
+ }
+
+ $this->id = (int)$id;
+ $this->text = (string)$text;
+ $this->message = $message
+ ?: new RawMessage(
+ '$1',
+ [ Message::plaintextParam( $this->text ) ]
+ );
$this->data = $data;
}