]> source.dussan.org Git - 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>
Sat, 28 Feb 2015 10:31:47 +0000 (10:31 +0000)
src/libutil/util.c
test/lua/unit/utf.lua [new file with mode: 0644]

index 5a42e4f8eb24ffb69ece2b346b9fb5a0b099608d..b2435dc8d5014f620b763e4ff9b658430984eea6 100644 (file)
@@ -692,6 +692,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