From: Vsevolod Stakhov Date: Wed, 7 Jul 2021 12:09:38 +0000 (+0100) Subject: [Minor] Limit whitespace trimming X-Git-Tag: 3.0~200 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc0d54237944801b29d509dd3fcb8ef9940f86fe;p=thirdparty%2Frspamd.git [Minor] Limit whitespace trimming --- diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx index 480a979e30..e0a57387e0 100644 --- a/src/libserver/html/html.cxx +++ b/src/libserver/html/html.cxx @@ -1093,12 +1093,14 @@ html_append_tag_content(rspamd_mempool_t *pool, if (is_visible) { if (!hc->parsed.empty() && hc->parsed.back() != c && hc->parsed.back() != '\n') { if (hc->parsed.back() == ' ') { - /* We also strip extra spaces at the end */ - hc->parsed.erase(std::find_if(hc->parsed.rbegin(), hc->parsed.rend(), + /* We also strip extra spaces at the end, but limiting the start */ + auto last = std::make_reverse_iterator(hc->parsed.begin() + initial_dest_offset); + auto first = std::find_if(hc->parsed.rbegin(), last, [](auto ch) -> auto { return ch != ' '; - }).base(), - hc->parsed.end()); + }); + hc->parsed.erase(first.base(), hc->parsed.end()); + g_assert(hc->parsed.size() >= initial_dest_offset); } hc->parsed.push_back(c); }