Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Mojo/DOM/CSS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ sub _compile {
if ($css =~ /\G\s*,\s*/gc) { push @$group, [] }

# Combinator
elsif ($css =~ /\G\s*([ >+~])\s*/gc) {
elsif ($css =~ /\G\s*([ \t>+~])\s*/gc) {
push @$last, ['pc', 'scope'] unless @$last;
push @$selectors, $1;
}

# Class or ID
elsif ($css =~ /\G([.#])((?:$ESCAPE_RE\s|\\.|[^,.#:[ >~+])+)/gco) {
elsif ($css =~ /\G([.#])((?:$ESCAPE_RE\s|\\.|[^,.#:[ \t>~+])+)/gco) {
my ($name, $op) = $1 eq '.' ? ('class', '~') : ('id', '');
push @$last, ['attr', _name($name), _value($op, $2)];
}
Expand Down Expand Up @@ -124,7 +124,7 @@ sub _compile {
}

# Tag
elsif ($css =~ /\G((?:$ESCAPE_RE\s|\\.|[^,.#:[ >~+])+)/gco) {
elsif ($css =~ /\G((?:$ESCAPE_RE\s|\\.|[^,.#:[ \t>~+])+)/gco) {
my $alias = (my $name = $1) =~ s/^([^|]*)\|// && $1 ne '*' ? $1 : undef;
my $ns = length $alias ? $ns{$alias} // return [['invalid']] : $alias;
push @$last, ['tag', $name eq '*' ? undef : _name($name), _unescape($ns)];
Expand Down
11 changes: 11 additions & 0 deletions t/mojo/dom.t
Original file line number Diff line number Diff line change
Expand Up @@ -3100,4 +3100,15 @@ subtest 'Unknown CSS selector' => sub {
like $@, qr/Unknown CSS selector: p\[/, 'right error';
};

subtest 'Handle tab in selector' => sub {
my $dom = Mojo::DOM->new(<<EOF);
<!DOCTYPE html>
<ul> <li>Ax1</li> </ul>
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

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

}
};

done_testing();
Loading