Skip to content

Conversation

@kent13n
Copy link
Contributor

@kent13n kent13n commented Mar 14, 2025

Description

This PR fixes a TypeError that occurs when retrieving innerText from an element that contains a <style> tag. The issue happens because the <style> tag introduces a CdataSection, which was not properly handled in the traversal process.
Related to the issue described in #460.

Fix:

The fix ensures that CdataSection nodes (introduced by <style> tags) are correctly handled during traversal.

  • Updated Traversal::getNextNode()
    • Added a condition to check if the node is an instance of CdataSection.
    • If it is, we apply NodeFilter::FILTER_REJECT to exclude it from traversal.
  • Updated Traversal::nextSkippingChildren()
    • Allowed CdataSection as a valid type for the $node parameter.

Impact:

Prevents crashes when processing innerText of elements containing <style> tags

@g105b g105b merged commit b73d7e8 into phpgt:master Mar 21, 2025
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when retrieving innerText from an element containing a <style> tag

2 participants