From 5fc656a1b8acd8e1207bd64dfbb5d1bdcde81ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 23 Dec 2022 23:20:29 +0100 Subject: [PATCH] api: fix function strcmp_ignore_chars with case sensitive comparison and wide chars starting with the same byte --- ChangeLog.adoc | 1 + src/core/wee-string.c | 2 +- tests/unit/core/test-core-string.cpp | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index a4f33d3f8..027c17385 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -36,6 +36,7 @@ Bug fixes:: * core: fix context info in buffers with free content (issue #1832) * core: keep terminal title unchanged when option weechat.look.window_title is set to empty value (issue #1835, issue #1836) * core: fix crash when setting invalid color in option with null value (issue #1844) + * api: fix function strcmp_ignore_chars with case sensitive comparison and wide chars starting with the same byte * api: send NULL values to config section callbacks in scripting API (issue #1843) * api: fix function string_cut when there are non printable chars in suffix * api: do not expect any return value in callbacks "callback_change" and "callback_delete" of function config_new_option (scripting API) diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 14bc245e0..4bf43094e 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -583,7 +583,7 @@ string_strcmp_ignore_chars (const char *string1, const char *string2, /* look at diff */ diff = (case_sensitive) ? - (int)string1[0] - (int)string2[0] : utf8_charcasecmp (string1, string2); + utf8_charcmp (string1, string2) : utf8_charcasecmp (string1, string2); if (diff != 0) return (diff < 0) ? -1 : 1; diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 24a557cb5..3dbcfbc78 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -566,6 +566,9 @@ TEST(CoreString, Comparison) LONGS_EQUAL(1, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0)); LONGS_EQUAL(-1, string_strcmp_ignore_chars (".", "..abcabc", ".", 0)); LONGS_EQUAL(0, string_strcmp_ignore_chars (".", ".", ".", 0)); + LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 0)); + LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "É", "", 0)); + LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 1)); } /*