Skip to content

Commit fbb3f05

Browse files
committed
bug #49195 [Crawler] Fix regression where cdata nodes will return empty string (NanoSector)
This PR was submitted for the 6.4 branch but it was merged into the 6.3 branch instead. Discussion ---------- [Crawler] Fix regression where cdata nodes will return empty string | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Fixes a regression caused by the fix to #48682 where `<script>` tags would return empty string on the innerContent call, where in 6.2 this did work. Attached is a zipped PHPUnit test case used to verify the regression on 6.2 with a screenshot of its result. [CrawlerInnerTextTest.zip](https://github.com/symfony/symfony/files/10567760/CrawlerInnerTextTest.zip) ![image](https://user-images.githubusercontent.com/1280380/216297235-1eda66d3-6768-4e49-9812-2857cff67086.png) Commits ------- 23c1dda [Crawler] Fix regression where cdata nodes will return empty string
2 parents ea5f2e0 + 23c1dda commit fbb3f05

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy