diff --git a/core/modules/node/node.preview.js b/core/modules/node/node.preview.js index 071d190fd8f35b0c81f5a0661cdc18014d4a79a5..50bc58ade7742f30dbc000e2a51c0e951e60e213 100644 --- a/core/modules/node/node.preview.js +++ b/core/modules/node/node.preview.js @@ -46,7 +46,7 @@ { text: Drupal.t('Leave preview'), click() { - window.top.location.href = event.target.href; + window.top.location.href = event.currentTarget.href; }, }, ], diff --git a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php index 2a80ebe41452d5091331a36d00277f88f10aef06..33a8795a6498bbc6c6e1329b45aee1191e44ed66 100644 --- a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php +++ b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php @@ -54,15 +54,29 @@ public function testPreviewLinks(): void { $assertSession = $this->assertSession(); $this->drupalGet('node/add/test'); $this->submitForm([ - 'title[0][value]' => 'Test node', - 'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>', + 'title[0][value]' => 'Test anchor link', + 'body[0][value]' => '<a href="#foo">Anchor link</a>', ], 'Preview'); $this->clickLink('Anchor link'); $assertSession->pageTextNotContains('Leave preview?'); + $this->drupalGet('node/add/test'); + $this->submitForm([ + 'title[0][value]' => 'Test normal link', + 'body[0][value]' => '<a href="/foo">Normal link</a>', + ], 'Preview'); $this->clickLink('Normal link'); $assertSession->pageTextContains('Leave preview?'); $this->click('button:contains("Leave preview")'); $this->assertStringEndsWith('/foo', $this->getUrl()); + $this->drupalGet('node/add/test'); + $this->submitForm([ + 'title[0][value]' => 'Test child element link', + 'body[0][value]' => '<a href="/foo" class="preview-child-element"><span>Child element link</span></a>', + ], 'Preview'); + $this->getSession()->getPage()->find('css', '.preview-child-element span')->click(); + $assertSession->pageTextContains('Leave preview?'); + $this->click('button:contains("Leave preview")'); + $this->assertStringEndsWith('/foo', $this->getUrl()); } }