Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError when retrieving innerText from elements containing <style> #461

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kent13n
Copy link

@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

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.

1 participant