]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Limit whitespace trimming
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 7 Jul 2021 12:09:38 +0000 (13:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 7 Jul 2021 12:09:38 +0000 (13:09 +0100)
src/libserver/html/html.cxx

index 480a979e30abc04d673060f67d749bf705399384..e0a57387e098b7516f0890fda8a0163e8268551d 100644 (file)
@@ -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);
                        }