Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c88cda

Browse files
committed
[Crawler] Fix regression where cdata nodes will return empty string
1 parent 268e740 commit 2c88cda

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public function innerText(/* bool $normalizeWhitespace = true */): string
588588
$normalizeWhitespace = 1 <= \func_num_args() ? func_get_arg(0) : true;
589589

590590
foreach ($this->getNode(0)->childNodes as $childNode) {
591-
if (\XML_TEXT_NODE !== $childNode->nodeType) {
591+
if (\XML_TEXT_NODE !== $childNode->nodeType && \XML_CDATA_SECTION_NODE !== $childNode->nodeType) {
592592
continue;
593593
}
594594
if (!$normalizeWhitespace) {

src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ public static function provideInnerTextExamples()
377377
'',
378378
' ',
379379
],
380+
[
381+
'//*[@id="complex-elements"]/*[@class="six"]',
382+
'console.log("Test JavaScript content");',
383+
'console.log("Test JavaScript content");',
384+
' console.log("Test JavaScript content"); ',
385+
],
380386
];
381387
}
382388

@@ -1311,6 +1317,7 @@ public function createTestCrawler($uri = null)
13111317
<div class="three"> Parent text <span>Child text</span> Parent text </div>
13121318
<div class="four"> <span>Child text</span> </div>
13131319
<div class="five"><span>Child text</span> <span>Another child</span></div>
1320+
<script class="six" type="text/javascript"> console.log("Test JavaScript content"); </script>
13141321
</div>
13151322
</body>
13161323
</html>

0 commit comments

Comments
 (0)