From: Vsevolod Stakhov Date: Fri, 22 Jan 2021 15:42:31 +0000 (+0000) Subject: [Project] Make unescape code public for unit testing X-Git-Tag: 3.0~739 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1712f32a3416a2ee329867502e5a383e80f72051;p=rspamd.git [Project] Make unescape code public for unit testing --- 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 #include #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; +}