From: Vsevolod Stakhov Date: Sat, 28 Feb 2015 10:31:47 +0000 (+0000) Subject: Add utf lc test case and fix the bug. X-Git-Tag: 0.8.2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08f73b6a844691f2dd8d01f27570a577e44de5d8;p=thirdparty%2Frspamd.git Add utf lc test case and fix the bug. --- diff --git a/src/libutil/util.c b/src/libutil/util.c index f0d9e0eb60..7d304dccb1 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -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 index 0000000000..2549c501c5 --- /dev/null +++ b/test/lua/unit/utf.lua @@ -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