From: Vsevolod Stakhov
Date: Wed, 7 Jul 2021 16:33:42 +0000 (+0100)
Subject: [Minor] Moar fixes for spaces stuff in html
X-Git-Tag: 3.0~198
X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7f57a9c6c66471d9b478e99c51d1b792183b38d;p=thirdparty%2Frspamd.git
[Minor] Moar fixes for spaces stuff in html
---
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index e0a57387e0..a6fcfe36bb 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -1011,14 +1011,20 @@ static inline auto
html_append_content(struct html_content *hc, std::string_view data, bool transparent) -> auto
{
auto cur_offset = hc->parsed.size();
- hc->parsed.append(data);
- if (cur_offset > 0 && data.size() > 0) {
- auto last = hc->parsed.back();
- auto first_appended = data.front();
- if (first_appended == ' ' && !g_ascii_isspace(last)) {
- cur_offset++;
+ if (data.size() > 0) {
+ /* Handle multiple spaces at the begin */
+
+ if (cur_offset > 0) {
+ auto last = hc->parsed.back();
+ if (!g_ascii_isspace(last) && g_ascii_isspace(data.front())) {
+ hc->parsed.append(" ");
+ data = {data.data() + 1, data.size() - 1};
+ cur_offset ++;
+ }
}
+
+ hc->parsed.append(data);
}
auto nlen = decode_html_entitles_inplace(hc->parsed.data() + cur_offset,
@@ -2075,7 +2081,7 @@ TEST_CASE("html text extraction")
"
\n"
" stuff?\n"
"