diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index f89d149..a6bfb2d 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1959,8 +1959,9 @@ function comment_unpublish_action(Comment $comment = NULL, $context = array()) {
  * @see comment_unpublish_by_keyword_action_submit()
  */
 function comment_unpublish_by_keyword_action(Comment $comment, $context) {
+  $build = comment_view($comment);
+  $text = drupal_render($build);
   foreach ($context['keywords'] as $keyword) {
-    $text = drupal_render($comment);
     if (strpos($text, $keyword) !== FALSE) {
       $comment->status = COMMENT_NOT_PUBLISHED;
       watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php
index 4a2e9ca..f4e8a35 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php
@@ -17,7 +17,7 @@ class CommentActionsTest extends CommentTestBase {
    *
    * @var array
    */
-  public static $modules = array('dblog');
+  public static $modules = array('dblog', 'action');
 
   public static function getInfo() {
     return array(
@@ -62,6 +62,28 @@ function testCommentPublishUnpublishActions() {
   }
 
   /**
+   * Tests comment unpublish by keyword.
+   */
+  function testCommentUnpublishKeywordTest() {
+    $this->drupalLogin($this->admin_user);
+    $keyword_1 = $this->randomName();
+    $keyword_2 = $this->randomName();
+    $aid = action_save('comment_unpublish_by_keyword_action', 'comment', array('keywords' => array($keyword_1, $keyword_2)), $this->randomName());
+
+    $this->assertTrue(action_load($aid), 'The action could be loaded.');
+
+    $comment = $this->postComment($this->node, $keyword_2, $this->randomName());
+
+    // Load the full comment so that status is available.
+    $comment = comment_load($comment->id);
+
+    $this->assertTrue($comment->status == COMMENT_PUBLISHED, 'The comment status was set to published.');
+
+    actions_do($aid, $comment, array());
+    $this->assertTrue($comment->status == COMMENT_NOT_PUBLISHED, 'The comment status was set to not published.');
+  }
+
+  /**
    * Verifies that a watchdog message has been entered.
    *
    * @param $watchdog_message
