From 9245e68bc74587314ccaaa4cf0ff02337a5ca6c8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 22 Jun 2021 17:13:59 +0100 Subject: [PATCH] [Project] Html: Fix crossing spans --- src/libserver/html/html.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx index 37d464c1d..d1bc508a6 100644 --- a/src/libserver/html/html.cxx +++ b/src/libserver/html/html.cxx @@ -1145,7 +1145,7 @@ html_append_tag_content(const gchar *start, gsize len, } } - if (!nested_stack.empty() && next_enclosed) { + if (next_enclosed) { /* Recursively print enclosed tags */ std::reverse(std::begin(nested_stack), std::end(nested_stack)); cur_offset = html_append_tag_content(start, len, hc, next_enclosed, nested_stack); @@ -1186,6 +1186,10 @@ html_append_tags_content(const gchar *start, gsize len, if (next_tag->content_offset <= next_offset) { enclosed_tags_stack.push_back(next_tag); + if (next_tag->content_offset + next_tag->content_length > next_offset) { + /* Tag spans over its parent */ + next_offset = next_tag->content_offset + next_tag->content_length; + } j ++; } else { @@ -1781,14 +1785,13 @@ TEST_CASE("html text extraction") { const std::vector> cases{ - {"foobarbaz", "foobarbaz"}, - {"foobarbaz", "foobarbaz"}, {"test", "test"}, {"test ", "test "}, {"test foo, bar", "test foo, bar"}, {"

text

", "text\n"}, {"olo

text

lolo", "olo\ntext\nlolo"}, - + {"foobarbaz", "foobarbaz"}, + {"foobarbaz", "foobarbaz"}, {"foo
baz", "foo\nbaz"}, {"
foo
bar
", "foo\nbar\n"}, }; -- 2.39.5