commit b53bea9: [Minor] Improve style from the previous merge

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Mar 9 14:28:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-09 14:23:23 +0000
URL: https://github.com/rspamd/rspamd/commit/b53bea90eb9593530258eb05f7066f53b050410e (HEAD -> master)

[Minor] Improve style from the previous merge

---
 src/libserver/html.c | 26 ++++----------------------
 src/libserver/url.h  |  1 -
 src/lua/lua_url.c    |  4 ++--
 3 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/src/libserver/html.c b/src/libserver/html.c
index c831dc14e..1f11f0cb2 100644
--- a/src/libserver/html.c
+++ b/src/libserver/html.c
@@ -2377,28 +2377,10 @@ rspamd_html_check_displayed_url (rspamd_mempool_t *pool,
 		return;
 	}
 
-	url->visible_part = rspamd_mempool_alloc0(pool, dest->len - href_offset+1);
-	gchar *current_processed_char = dest->data + href_offset;
-	gchar *current_char_in_struct = url->visible_part;
-	gboolean previous_char_was_space = false;
-
-	while (current_processed_char < (gchar*) dest->data + dest->len) {
-		if (g_ascii_isspace(*current_processed_char)) {
-			if (previous_char_was_space) {
-				current_processed_char++;
-				continue;
-			}
-			previous_char_was_space = true;
-			*current_char_in_struct = ' ';
-		} else {
-			*current_char_in_struct = *current_processed_char;
-			previous_char_was_space = false;
-		}
-		current_char_in_struct++;
-		current_processed_char++;
-	}
-	*current_char_in_struct = '\0';
-	url->visible_partlen = current_char_in_struct - url->visible_part;
+	url->visible_part = rspamd_mempool_alloc (pool, dest->len - href_offset + 1);
+	rspamd_strlcpy (url->visible_part, dest->data + href_offset,
+			dest->len - href_offset + 1);
+	g_strstrip (url->visible_part);
 
 	rspamd_html_url_is_phished (pool, url,
 			dest->data + href_offset,
diff --git a/src/libserver/url.h b/src/libserver/url.h
index ad09c33ec..2cf80df4b 100644
--- a/src/libserver/url.h
+++ b/src/libserver/url.h
@@ -63,7 +63,6 @@ struct rspamd_url {
 	guint tldlen;
 	guint urllen;
 	guint rawlen;
-	guint visible_partlen;
 
 	enum rspamd_url_flags flags;
 	guint count;
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 58c6a83be..9bc984da3 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -663,8 +663,8 @@ lua_url_get_visible (lua_State *L)
 	LUA_TRACE_POINT;
 	struct rspamd_lua_url *url = lua_check_url (L, 1);
 
-	if (url != NULL) {
-		lua_pushlstring (L, url->url->visible_part, url->url->visible_partlen);
+	if (url != NULL && url->url->visible_part) {
+		lua_pushstring (L, url->url->visible_part);
 	}
 	else {
 		lua_pushnil (L);


More information about the Commits mailing list