]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Make unescape code public for unit testing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jan 2021 15:42:31 +0000 (15:42 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jan 2021 15:58:05 +0000 (15:58 +0000)
src/libserver/css/css.h
src/libserver/css/css.hxx
src/libserver/css/css_parser.cxx

index 169bcf58c001a51e04591b4c61c3aefca2b29c75..78f24a5494b4dd7283c1f1ca507f10b915b73c5c 100644 (file)
@@ -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
index d258b35c94438923ea12e2d3dbb3b195344a653a..8f2550d7b1c55bf17739775190af68c0d8f0de4f 100644 (file)
@@ -19,6 +19,7 @@
 #include <string>
 #include <memory>
 #include "logger.h"
+#include "css.h"
 
 namespace rspamd::css {
 
index 9f2023e50bdc8c9bec5351f6f4984b953388e4a1..99798b8443c9413f94e34ca2110f17e8b0d14aa5 100644 (file)
@@ -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;
+}