Skip to content

Commit e17bd94

Browse files
author
Timofey Potapov
committed
Fixed: Mojo::DOM doesn't recognize end of comment mojolicious#2029 mojolicious#2030.
1 parent 3680265 commit e17bd94

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

lib/Mojo/DOM/HTML.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ my $TOKEN_RE = qr/
2929
(?:\s+\[.+?\])? # Int Subset
3030
\s*)
3131
|
32-
--(.*?)--\s* # Comment
32+
--(?|()-*!?(?=>)|(.*?)--!?(?=>)) # Comment
3333
|
3434
\[CDATA\[(.*?)\]\] # CDATA
3535
)

t/mojo/dom.t

+52-4
Original file line numberDiff line numberDiff line change
@@ -2643,10 +2643,58 @@ subtest 'Comments' => sub {
26432643
<!-- HTML4 -- >
26442644
<!-- bad idea -- HTML4 -- >
26452645
EOF
2646-
is $dom->tree->[1][1], ' HTML5 ', 'right comment';
2647-
is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
2648-
is $dom->tree->[5][1], ' HTML4 ', 'right comment';
2649-
is $dom->tree->[7][1], ' bad idea -- HTML4 ', 'right comment';
2646+
is $dom->tree->[1][1], ' HTML5 ', 'right comment';
2647+
is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
2648+
is $dom->tree->[5][1], '<', 'wrong comment';
2649+
is $dom->tree->[6][1], "!-- HTML4 -- >\n", 'wrong comment';
2650+
is $dom->tree->[7][1], '<', 'wrong comment';
2651+
is $dom->tree->[8][1], "!-- bad idea -- HTML4 -- >\n", 'wrong comment';
2652+
2653+
$dom = Mojo::DOM->new('<!--> <p>OK</p> <!-- -->');
2654+
is $dom->tree->[1][0], 'comment', 'right node';
2655+
is $dom->tree->[1][1], '', 'right text';
2656+
is $dom->tree->[2][0], 'text', 'right node';
2657+
is $dom->tree->[2][1], ' ', 'right text';
2658+
is $dom->tree->[3][0], 'tag', 'right node';
2659+
is $dom->tree->[3][1], 'p', 'right text';
2660+
is $dom->tree->[3][4][0], 'text', 'right node';
2661+
is $dom->tree->[3][4][1], 'OK', 'right text';
2662+
is $dom->tree->[4][0], 'text', 'right node';
2663+
is $dom->tree->[4][1], ' ', 'right text';
2664+
is $dom->tree->[5][0], 'comment', 'right node';
2665+
is $dom->tree->[5][1], ' ', 'right text';
2666+
2667+
$dom = Mojo::DOM->new('<!---> <p>OK</p> <!-- -->');
2668+
is $dom->tree->[1][0], 'comment', 'right node';
2669+
is $dom->tree->[1][1], '', 'right text';
2670+
is $dom->tree->[2][0], 'text', 'right node';
2671+
is $dom->tree->[2][1], ' ', 'right text';
2672+
is $dom->tree->[3][0], 'tag', 'right node';
2673+
is $dom->tree->[3][1], 'p', 'right text';
2674+
is $dom->tree->[3][4][0], 'text', 'right node';
2675+
is $dom->tree->[3][4][1], 'OK', 'right text';
2676+
is $dom->tree->[4][0], 'text', 'right node';
2677+
is $dom->tree->[4][1], ' ', 'right text';
2678+
is $dom->tree->[5][0], 'comment', 'right node';
2679+
is $dom->tree->[5][1], ' ', 'right text';
2680+
2681+
$dom = Mojo::DOM->new('<!-- --!> <p>OK</p> <!-- -->');
2682+
is $dom->tree->[1][0], 'comment', 'right node';
2683+
is $dom->tree->[1][1], ' ', 'right text';
2684+
is $dom->tree->[2][0], 'text', 'right node';
2685+
is $dom->tree->[2][1], ' ', 'right text';
2686+
is $dom->tree->[3][0], 'tag', 'right node';
2687+
is $dom->tree->[3][1], 'p', 'right text';
2688+
is $dom->tree->[3][4][0], 'text', 'right node';
2689+
is $dom->tree->[3][4][1], 'OK', 'right text';
2690+
is $dom->tree->[4][0], 'text', 'right node';
2691+
is $dom->tree->[4][1], ' ', 'right text';
2692+
is $dom->tree->[5][0], 'comment', 'right node';
2693+
is $dom->tree->[5][1], ' ', 'right text';
2694+
2695+
$dom = Mojo::DOM->new('<!-- a > -- > b <blink>c</blink> -->');
2696+
is $dom->tree->[1][0], 'comment', 'right node';
2697+
is $dom->tree->[1][1], ' a > -- > b <blink>c</blink> ', 'right text';
26502698
};
26512699

26522700
subtest 'Huge number of attributes' => sub {

0 commit comments

Comments
 (0)