diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index bb203bf..eb93196 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -661,11 +661,11 @@ function template_preprocess_comment(&$variables) { else { $uri = $comment->permalink(); $attributes = $uri->getOption('attributes') ?: []; - $attributes += ['class' => ['permalink'], 'rel' => 'bookmark']; + $attributes += ['class' => ['permalink'], 'rel' => 'bookmark nofollow']; $uri->setOption('attributes', $attributes); $variables['title'] = \Drupal::l($comment->getSubject(), $uri); - $variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink()); + $variables['permalink'] = \Drupal::l(t('Permalink'), $uri); } $variables['submitted'] = t('Submitted by @username on @datetime', ['@username' => $variables['author'], '@datetime' => $variables['created']]); @@ -690,7 +690,7 @@ function template_preprocess_comment(&$variables) { } $permalink_uri_parent = $comment_parent->permalink(); $attributes = $permalink_uri_parent->getOption('attributes') ?: []; - $attributes += ['class' => ['permalink'], 'rel' => 'bookmark']; + $attributes += ['class' => ['permalink'], 'rel' => 'bookmark nofollow']; $permalink_uri_parent->setOption('attributes', $attributes); $variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent); $variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent); diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php index 7342633..e3293dd 100644 --- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php @@ -80,10 +80,11 @@ public function testCommentInterface() { $this->assertText($comment_text, 'Individual comment body found.'); $arguments = [ ':link' => base_path() . 'comment/' . $comment->id() . '#comment-' . $comment->id(), + ':rel' => 'nofollow', ]; - $pattern_permalink = '//footer[contains(@class,"comment__meta")]/a[contains(@href,:link) and text()="Permalink"]'; + $pattern_permalink = '//footer[contains(@class,"comment__meta")]/a[contains(@href,:link) and contains(@rel,:rel) and text()="Permalink"]'; $permalink = $this->xpath($pattern_permalink, $arguments); - $this->assertTrue(!empty($permalink), 'Permalink link found.'); + $this->assertTrue(!empty($permalink), 'Permalink link found and rel is set to nofollow.'); // Set comments to have subject and preview to optional. $this->drupalLogout(); diff --git a/core/modules/comment/tests/src/Functional/CommentTitleTest.php b/core/modules/comment/tests/src/Functional/CommentTitleTest.php index 65c4937..041bfd3 100644 --- a/core/modules/comment/tests/src/Functional/CommentTitleTest.php +++ b/core/modules/comment/tests/src/Functional/CommentTitleTest.php @@ -77,6 +77,10 @@ public function testCommentPopulatedTitles() { // Tests that the comment's title link contains the url fragment. $this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment."); $this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link."); + + $comment_permalink_rel = $comment_permalink[0]->getAttribute('rel'); + // Tests that the comment's title link contains the nofollow rel. + $this->assertTrue(strpos($comment_permalink_rel, 'nofollow'), "The comment's title link contains the nofollow rel."); } }