From 58605fe601b92bac83549cd4ff9da6b10257a122 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Tue, 15 Dec 2020 08:03:44 +1000
Subject: [PATCH] Revert "Issue #2454915 by SaschaHannes, anevins, Spokje,
 ducktape, joseph.olstad, marcoliver, dschenk, Dom., larowlan, isholgueras:
 Entity link annotations in HTML head are not valid HTML"

This reverts commit 9d4138cb81ace1d8a7ee041776cf13ea281604e4.
---
 .../src/Controller/NodeViewController.php     | 47 +------------------
 .../tests/src/Functional/NodeViewTest.php     | 26 +++++++++-
 2 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/core/modules/node/src/Controller/NodeViewController.php b/core/modules/node/src/Controller/NodeViewController.php
index 96b9a86b41bb..a0787d4abccc 100644
--- a/core/modules/node/src/Controller/NodeViewController.php
+++ b/core/modules/node/src/Controller/NodeViewController.php
@@ -77,7 +77,7 @@ public function view(EntityInterface $node, $view_mode = 'full', $langcode = NUL
       // This means that the page will vary by user.permissions. We also rely on
       // the access checking fallback to ensure the correct cacheability
       // metadata if we have to check access.
-      if ($this->isValidRel($rel) && ($this->currentUser->isAuthenticated() || $url->access($this->currentUser))) {
+      if ($this->currentUser->isAuthenticated() || $url->access($this->currentUser)) {
         // Set the node path as the canonical URL to prevent duplicate content.
         $build['#attached']['html_head_link'][] = [
           [
@@ -123,49 +123,4 @@ public function title(EntityInterface $node) {
     return $this->entityRepository->getTranslationFromContext($node)->label();
   }
 
-  /**
-   * Checks if rel attribute is w3c.org valid
-   *
-   * @param string $rel
-   *   The unchecked rel attribute.
-   *
-   * @return bool
-   *   The valid state
-   *
-   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
-   */
-  private function isValidRel($rel) : bool {
-    // List of all supported rel tags.
-    $validRelList = [
-      'alternate',
-      'author',
-      'bookmark',
-      'canonical',
-      'dns-prefetch',
-      'external',
-      'help',
-      'icon',
-      'license',
-      'manifest',
-      'modulepreload',
-      'next',
-      'nofollow',
-      'noopener',
-      'noreferrer',
-      'opener',
-      'pingback',
-      'preconnect',
-      'prefetch',
-      'preload',
-      'prerender',
-      'prev',
-      'search',
-      'shortcut icon',
-      'shortlink',
-      'stylesheet',
-      'tag',
-    ];
-    return in_array($rel, $validRelList, TRUE);
-  }
-
 }
diff --git a/core/modules/node/tests/src/Functional/NodeViewTest.php b/core/modules/node/tests/src/Functional/NodeViewTest.php
index 4c5b6ccb86ba..772df968c53f 100644
--- a/core/modules/node/tests/src/Functional/NodeViewTest.php
+++ b/core/modules/node/tests/src/Functional/NodeViewTest.php
@@ -43,10 +43,31 @@ public function testHtmlHeadLinks() {
 
     // Link relations are present regardless of access for authenticated users.
     $result = $this->xpath('//link[@rel = "version-history"]');
-    $this->assertEmpty($result);
+    $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('version-history')->setAbsolute()->toString());
 
     $result = $this->xpath('//link[@rel = "edit-form"]');
-    $this->assertEmpty($result);
+    $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString());
+
+    // Give anonymous users access to edit the node. Do this through the UI to
+    // ensure caches are handled properly.
+    $this->drupalLogin($this->rootUser);
+    $edit = [
+      'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE,
+    ];
+    $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions');
+    $this->drupalLogout();
+
+    // Anonymous user's should now see the edit-form link but not the
+    // version-history link.
+    $this->drupalGet($node->toUrl());
+    $result = $this->xpath('//link[@rel = "canonical"]');
+    $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString());
+
+    $result = $this->xpath('//link[@rel = "version-history"]');
+    $this->assertEmpty($result, 'Version history not present for anonymous users without access.');
+
+    $result = $this->xpath('//link[@rel = "edit-form"]');
+    $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString());
   }
 
   /**
@@ -58,6 +79,7 @@ public function testLinkHeader() {
     $expected = [
       '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString()) . '>; rel="canonical"',
       '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString(), ['alias' => TRUE]) . '>; rel="shortlink"',
+      '<' . Html::escape($node->toUrl('revision')->setAbsolute()->toString()) . '>; rel="revision"',
     ];
 
     $this->drupalGet($node->toUrl());
-- 
GitLab