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

Mojo::DOM doesn't handle whitespace in selectors correctly #2024

Open
mauke opened this issue Jan 23, 2023 · 1 comment
Open

Mojo::DOM doesn't handle whitespace in selectors correctly #2024

mauke opened this issue Jan 23, 2023 · 1 comment

Comments

@mauke
Copy link
Contributor

mauke commented Jan 23, 2023

  • Mojolicious version: 9.31
  • Perl version: v5.36.0
  • Operating system: Linux (Ubuntu 22.04)

Steps to reproduce the behavior

#!/usr/bin/env perl
use v5.14.0;
use warnings;
use Test::More;
use Mojo::DOM;

my $dom = Mojo::DOM->new(<<'_EOT_');
<!DOCTYPE html>
<ul> <li>Ax1</li> </ul>
_EOT_

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 . '"';
}

done_testing;

Expected behavior

Test passes.

https://www.w3.org/TR/selectors-3/#descendant-combinators:

A descendant combinator is whitespace that separates two sequences of simple selectors.

Actual behavior

ok 1 - selector "ul li"
not ok 2 - selector "ul\tli"
#   Failed test 'selector "ul\tli"'
#   at mojo-dom-bug-4.pl line 19.
#     Structures begin differing at:
#          $got->[0] = Does not exist
#     $expected->[0] = '<li>Ax1</li>'
ok 3 - selector "ul \tli"
not ok 4 - selector "ul\t li"
#   Failed test 'selector "ul\t li"'
#   at mojo-dom-bug-4.pl line 19.
#     Structures begin differing at:
#          $got->[0] = Does not exist
#     $expected->[0] = '<li>Ax1</li>'
1..4
# Looks like you failed 2 tests of 4.
@kraih kraih added the bug label Jan 29, 2023
@kraih
Copy link
Member

kraih commented Jan 29, 2023

While technically a bug, the use cases here seem rather limited, so i'd call this pretty low priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants