Skip to content

Commit

Permalink
[Crawler] Fix regression where cdata nodes will return empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoSector authored and fabpot committed Aug 1, 2023
1 parent 8aa333f commit 3fdd2a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions Tests/AbstractCrawlerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"); ',
],
];
}

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

0 comments on commit 3fdd2a3

Please sign in to comment.