From e866150369bfbdf594612b53262f0ad7aa5d3524 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 28 Feb 2015 10:31:47 +0000 Subject: [PATCH] Add utf lc test case and fix the bug. --- src/libutil/util.c | 1 + test/lua/unit/utf.lua | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/lua/unit/utf.lua diff --git a/src/libutil/util.c b/src/libutil/util.c index 5a42e4f8e..b2435dc8d 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -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 index 000000000..2549c501c --- /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 -- 2.39.5