diff --git a/core/modules/aggregator/src/Tests/AddFeedTest.php b/core/modules/aggregator/src/Tests/AddFeedTest.php index 2a7f037..b66ac55 100644 --- a/core/modules/aggregator/src/Tests/AddFeedTest.php +++ b/core/modules/aggregator/src/Tests/AddFeedTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\aggregator\Tests; +use Drupal\Component\Utility\Html; /** * Add feed test. @@ -45,6 +46,23 @@ public function testAddFeed() { } /** + * Ensures that the feed label is escaping when rendering the feed icon. + */ + public function testFeedLabelEscaping() { + $feed = $this->createFeed(NULL, ['title[0][value]' => 'Test feed title ']); + $this->checkForMetaRefresh(); + + $this->drupalGet('aggregator/sources/' . $feed->id()); + $this->assertResponse(200); + + $result = $this->xpath('//h1'); + $this->assertEqual((string) $result[0], 'Test feed title alert(123);'); + + // Ensure the feed icon title is escaped. + $this->assertRaw('class="feed-icon"> Subscribe to Test feed title <script>alert(123);</script> feed'); + } + + /** * Tests feeds with very long URLs. */ public function testAddLongFeed() { diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php index 87e8887..1457170 100644 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ b/core/modules/simpletest/src/AssertContentTrait.php @@ -818,6 +818,23 @@ protected function assertTitle($title, $message = '', $group = 'Other') { } /** + * Assertion helper to check the raw content of a specific tag. + * + * This is needed because xpath html decodes stuff. + */ + protected function assertRawTag($expected_html, $tag, array $classes = []) { + $attributes = ''; + if ($classes) { + $attributes = '.*class="' . implode(' ', $classes) . '".*'; + } + preg_match("@<$tag " . $attributes . ">([^<]*)@", str_replace(["\n", "\r"], '', $this->getRawContent()), $matches); + debug("@<$tag " . $attributes . ">([^<]*)@"); + debug($matches); + + debug($matches[1]); + } + + /** * Pass if the page title is not the given string. * * @param string $title