From e17bd94a496b2bf0af8ae3cf20b54797c60a4dca Mon Sep 17 00:00:00 2001 From: Timofey Potapov Date: Mon, 26 Jun 2023 22:15:55 +0200 Subject: [PATCH] Fixed: Mojo::DOM doesn't recognize end of comment #2029 #2030. --- lib/Mojo/DOM/HTML.pm | 2 +- t/mojo/dom.t | 56 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/Mojo/DOM/HTML.pm b/lib/Mojo/DOM/HTML.pm index e10b1532dd..5064c41a5d 100644 --- a/lib/Mojo/DOM/HTML.pm +++ b/lib/Mojo/DOM/HTML.pm @@ -29,7 +29,7 @@ my $TOKEN_RE = qr/ (?:\s+\[.+?\])? # Int Subset \s*) | - --(.*?)--\s* # Comment + --(?|()-*!?(?=>)|(.*?)--!?(?=>)) # Comment | \[CDATA\[(.*?)\]\] # CDATA ) diff --git a/t/mojo/dom.t b/t/mojo/dom.t index 151c4dfdf6..9aeb131463 100644 --- a/t/mojo/dom.t +++ b/t/mojo/dom.t @@ -2643,10 +2643,58 @@ subtest 'Comments' => sub {

OK

'); + is $dom->tree->[1][0], 'comment', 'right node'; + is $dom->tree->[1][1], '', '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('

OK

'); + is $dom->tree->[1][0], 'comment', 'right node'; + is $dom->tree->[1][1], '', '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('

OK

'); + is $dom->tree->[1][0], 'comment', 'right node'; + is $dom->tree->[1][1], ' ', '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(''); + is $dom->tree->[1][0], 'comment', 'right node'; + is $dom->tree->[1][1], ' a > -- > b c ', 'right text'; }; subtest 'Huge number of attributes' => sub {