Refactor Lexbor empty text detection to ASCII whitespace only, changing it from Lexbor's original lxb_dom_node_is_empty check!#198
Merged
rushter merged 7 commits intorushter:masterfrom Nov 29, 2025
Conversation
…space` for improved readability and code reuse.
…rmance and marking it as `nogil`.
…ly`, add `clean_doc` utility in tests, and enhance traversal test coverage.
…pace_only`, add docstrings, and enhance test formatting.
rushter
reviewed
Nov 28, 2025
…nction, simplify `_is_whitespace_only`, and replace internal calls for improved clarity and reusability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request updates the definition of "empty" text nodes in the Lexbor backend of selectolax, changing it from Lexbor's original
lxb_dom_node_is_emptycheck to a stricter check for nodes containing only ASCII whitespace (space, tab, newline, form feed, or carriage return). It also adds a new test to verify this behavior on a full HTML document and updates documentation throughout the codebase to reflect the new definition.Important
lxb_dom_node_is_empty is overkill for our needs, and it also causes some bugs with the previous implementation.
Behavioral changes:
_is_empty_text_nodemethod inLexborNodenow checks if a text node consists solely of ASCII whitespace, rather than using Lexbor'slxb_dom_node_is_empty. This is implemented via a new helper method_is_whitespace_only, which does an inline scan for whitespace characters. [1] [2]Testing:
test_traverse_with_skip_empty_on_a_full_html_document, is added to verify that traversal with and withoutskip_empty=Trueproduces the expected results, confirming the new whitespace-only logic.These changes make the definition of "empty" text nodes more predictable and easier to reason about, matching common expectations for HTML whitespace handling.