diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 274aeee5fc803..8274ee3ee5bf3 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -588,7 +588,7 @@ public function innerText(/* bool $normalizeWhitespace = true */): string $normalizeWhitespace = 1 <= \func_num_args() ? func_get_arg(0) : true; foreach ($this->getNode(0)->childNodes as $childNode) { - if (\XML_TEXT_NODE !== $childNode->nodeType) { + if (\XML_TEXT_NODE !== $childNode->nodeType && \XML_CDATA_SECTION_NODE !== $childNode->nodeType) { continue; } if (!$normalizeWhitespace) { diff --git a/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTestCase.php b/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTestCase.php index e682ff405a349..2a227b10574f9 100644 --- a/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTestCase.php +++ b/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTestCase.php @@ -377,6 +377,12 @@ public static function provideInnerTextExamples() '', ' ', ], + [ + '//*[@id="complex-elements"]/*[@class="six"]', + 'console.log("Test JavaScript content");', + 'console.log("Test JavaScript content");', + ' console.log("Test JavaScript content"); ', + ], ]; } @@ -1311,6 +1317,7 @@ public function createTestCrawler($uri = null)