Skip to content

Conversation

TFBW
Copy link
Contributor

@TFBW TFBW commented Jul 30, 2025

Summary

Fixes Mojo::DOM::CSS not handling certain tab characters correctly.

Motivation

Tabs were being incorrectly included in the Class/ID pattern and Tag pattern, and not included in the Combinator pattern.

References

Fixes #2024

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes CSS selector parsing in Mojo::DOM::CSS to properly handle tab characters in CSS selectors, ensuring tabs are treated consistently with spaces as whitespace separators.

  • Updated CSS selector regex patterns to include tab characters (\t) alongside spaces
  • Added comprehensive test coverage for various tab character scenarios in selectors
  • Fixed inconsistent handling where tabs were incorrectly included in some patterns but excluded from combinators

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/Mojo/DOM/CSS.pm Updated regex patterns to properly handle tab characters in CSS selector parsing
t/mojo/dom.t Added test cases to verify tab character handling in CSS selectors

EOF
for my $selector ("ul li", "ul\tli", "ul \tli", "ul\t li") {
is_deeply $dom->find($selector)->map(sub { $_->to_string })->to_array, ['<li>Ax1</li>'],
'selector "' . $selector =~ s/\t/\\t/r . '"';
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The regex substitution pattern s/\t/\\t/r is confusing with multiple backslashes. Consider using a more readable approach like $selector =~ tr/\t/t/ with 'tab' text or storing the display string separately.

Suggested change
'selector "' . $selector =~ s/\t/\\t/r . '"';
'selector "' . ($selector =~ tr/\t/t/r =~ s/^/\\/r) . '"';

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bogus

@@ -74,7 +74,7 @@ sub _combinator {
# "+" (immediately preceding siblings)
return _sibling($selectors, $current, $tree, $scope, 1, ++$pos) if $c eq '+';

# " " (ancestor)
# " " or "\t" (ancestor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to modify the comment

t/mojo/dom.t Outdated
@@ -3100,4 +3100,16 @@ subtest 'Unknown CSS selector' => sub {
like $@, qr/Unknown CSS selector: p\[/, 'right error';
};

# Github Issue #2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment serves no real purpose

@kraih
Copy link
Member

kraih commented Jul 31, 2025

Please squash commits.

@TFBW TFBW force-pushed the fix-dom-issues branch from ee32045 to fe8cb79 Compare July 31, 2025 13:31
@kraih
Copy link
Member

kraih commented Aug 1, 2025

There's two commits still.

@TFBW
Copy link
Contributor Author

TFBW commented Aug 1, 2025

Clearly, merging up main was a bad idea and my git-fu is weak.

@kraih
Copy link
Member

kraih commented Aug 1, 2025

Just rebase on main and force push.

@TFBW
Copy link
Contributor Author

TFBW commented Aug 1, 2025

Might have to sacrifice a goat just to be sure, but I'll try.

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.

Mojo::DOM doesn't handle whitespace in selectors correctly
3 participants