commit 1712f32: [Project] Make unescape code public for unit testing

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jan 22 16:00:33 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-01-22 15:42:31 +0000
URL: https://github.com/rspamd/rspamd/commit/1712f32a3416a2ee329867502e5a383e80f72051

[Project] Make unescape code public for unit testing

---
 src/libserver/css/css.h          |  8 ++++++++
 src/libserver/css/css.hxx        |  1 +
 src/libserver/css/css_parser.cxx | 22 ++++++++++++++++++++--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/libserver/css/css.h b/src/libserver/css/css.h
index 169bcf58c..78f24a549 100644
--- a/src/libserver/css/css.h
+++ b/src/libserver/css/css.h
@@ -28,6 +28,14 @@ typedef void * rspamd_css;
 rspamd_css rspamd_css_parse_style (rspamd_mempool_t *pool,
 								   const guchar *begin,
 								   gsize len, GError **err);
+
+/*
+ * Unescape css
+ */
+const gchar *rspamd_css_unescape (rspamd_mempool_t *pool,
+							const guchar *begin,
+							gsize len,
+							gsize *outlen);
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/libserver/css/css.hxx b/src/libserver/css/css.hxx
index d258b35c9..8f2550d7b 100644
--- a/src/libserver/css/css.hxx
+++ b/src/libserver/css/css.hxx
@@ -19,6 +19,7 @@
 #include <string>
 #include <memory>
 #include "logger.h"
+#include "css.h"
 
 namespace rspamd::css {
 
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 9f2023e50..99798b844 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -36,6 +36,9 @@ public:
 		return tl::make_unexpected (error);
 	}
 
+	/* Public for unit tests */
+	std::string_view unescape_css(const std::string_view &sv);
+
 private:
 	enum class parser_state {
 		initial_state,
@@ -51,8 +54,6 @@ private:
 
 	/* Helper parser methods */
 	bool need_unescape(const std::string_view &sv);
-
-	std::string_view unescape_css(const std::string_view &sv);
 };
 
 /*
@@ -236,3 +237,20 @@ auto parse_css(rspamd_mempool_t *pool, const std::string_view &st) ->
 }
 
 }
+
+/* C API */
+const gchar *rspamd_css_unescape (rspamd_mempool_t *pool,
+							const guchar *begin,
+							gsize len,
+							gsize *outlen)
+{
+	rspamd::css::css_parser parser(pool);
+	auto sv = parser.unescape_css({(const char*)begin, len});
+	const auto *v = sv.begin();
+
+	if (outlen) {
+		*outlen = sv.size();
+	}
+
+	return v;
+}


More information about the Commits mailing list