]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add utf lc test case and fix the bug.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Feb 2015 10:31:47 +0000 (10:31 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 2 Mar 2015 14:20:42 +0000 (14:20 +0000)
src/libutil/util.c
test/lua/unit/utf.lua [new file with mode: 0644]

index f0d9e0eb6033860fc9854fe7927d4c42acb947c3..7d304dccb165783bb461f462be440fcf99e23b9b 100644 (file)
@@ -686,6 +686,7 @@ rspamd_str_lc_utf8 (gchar *str, guint size)
                s = p;
                d += r;
        }
+       *d = '\0';
 }
 
 #ifndef HAVE_SETPROCTITLE
diff --git a/test/lua/unit/utf.lua b/test/lua/unit/utf.lua
new file mode 100644 (file)
index 0000000..2549c50
--- /dev/null
@@ -0,0 +1,23 @@
+-- Test utf routines
+
+context("UTF8 check functions", function()
+  local ffi = require("ffi")
+  ffi.cdef[[
+    void rspamd_str_lc_utf8 (char *str, unsigned int size);
+  ]]
+
+  test("UTF lowercase", function()
+    local cases = {
+      {"АбЫрвАлг", "абырвалг"},
+      {"АAБBвc", "аaбbвc"}
+    }
+    
+    for _,c in ipairs(cases) do
+      local buf = ffi.new("char[?]", #c[1])
+      ffi.copy(buf, c[1])
+      ffi.C.rspamd_str_lc_utf8(buf, #c[1])
+      local s = ffi.string(buf)
+      assert_equal(s, c[2])
+    end
+  end)
+end)
\ No newline at end of file