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

Fixed: Mojo::DOM doesn't recognize end of comment (when it should) #2… #2080

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion lib/Mojo/DOM/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ my $TOKEN_RE = qr/
(?:\s+\[.+?\])? # Int Subset
\s*)
|
--(.*?)--\s* # Comment
--(?|()-*!?(?=>)|(.*?)--!?(?=>)) # Comment
|
\[CDATA\[(.*?)\]\] # CDATA
)
Expand Down
31 changes: 27 additions & 4 deletions t/mojo/dom.t
Original file line number Diff line number Diff line change
Expand Up @@ -2643,10 +2643,33 @@ subtest 'Comments' => sub {
<!-- HTML4 -- >
<!-- bad idea -- HTML4 -- >
EOF
is $dom->tree->[1][1], ' HTML5 ', 'right comment';
is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
is $dom->tree->[5][1], ' HTML4 ', 'right comment';
is $dom->tree->[7][1], ' bad idea -- HTML4 ', 'right comment';
is $dom->tree->[1][1], ' HTML5 ', 'right comment';
is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
is $dom->tree->[5][1], '<', 'wrong comment';
is $dom->tree->[6][1], "!-- HTML4 -- >\n", 'wrong comment';
is $dom->tree->[7][1], '<', 'wrong comment';
is $dom->tree->[8][1], "!-- bad idea -- HTML4 -- >\n", 'wrong comment';

for ('<!-->', '<!--->', '<!-- --!>') {
Copy link
Member

Choose a reason for hiding this comment

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

$_ with such a wide scope is not good style.

Copy link
Member

Choose a reason for hiding this comment

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

In fact, i don't like loops in tests at all, they only make errors harder to find because line numbers get so much less useful.

my $dom = Mojo::DOM->new("$_ <p>OK</p> <!-- -->");
my $space = / / ? ' ' : '';
kraih marked this conversation as resolved.
Show resolved Hide resolved
is $dom->tree->[1][0], 'comment', "right node";
is $dom->tree->[1][1], $space, "right text";
is $dom->tree->[2][0], 'text', "right node";
is $dom->tree->[2][1], ' ', "right text";
is $dom->tree->[3][0], 'tag', "right node";
is $dom->tree->[3][1], 'p', "right text";
is $dom->tree->[3][4][0], 'text', "right node";
is $dom->tree->[3][4][1], 'OK', "right text";
is $dom->tree->[4][0], 'text', "right node";
is $dom->tree->[4][1], ' ', "right text";
is $dom->tree->[5][0], 'comment', "right node";
is $dom->tree->[5][1], ' ', "right text";
}

$dom = Mojo::DOM->new('<!-- a > -- > b <blink>c</blink> -->');
is $dom->tree->[1][0], 'comment', 'right node';
is $dom->tree->[1][1], ' a > -- > b <blink>c</blink> ', 'right text';
};

subtest 'Huge number of attributes' => sub {
Expand Down