From 41cb1bf635eb56b7189dbfbdb89432dca1f46ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 24 Aug 2015 11:05:31 +0200 Subject: [PATCH] api: fix handle of invalid escape in function string_convert_escaped_chars() And a new test is now checking that "\" returns "". --- ChangeLog.asciidoc | 1 + src/core/wee-string.c | 9 ++++++--- tests/unit/core/test-string.cpp | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index 822bf0bd8..77c20be06 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -29,6 +29,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] * core: fix truncated messages after a word with a length of zero on screen (for example a zero width space: U+200B) (bug #40985, issue #502) +* api: fix handle of invalid escape in function string_convert_escaped_chars() * irc: display the arrow before server name in raw buffer * irc: fix display of messages sent to server in raw buffer * irc: fix display of invalid UTF-8 chars in raw buffer diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 389d12c62..9ae23d7f3 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -787,9 +787,12 @@ string_convert_escaped_chars (const char *string) } break; default: - output[pos_output++] = '\\'; - output[pos_output++] = ptr_string[0]; - ptr_string++; + if (ptr_string[0]) + { + output[pos_output++] = '\\'; + output[pos_output++] = ptr_string[0]; + ptr_string++; + } break; } } diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp index dc33029cd..cf1a6c464 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-string.cpp @@ -460,6 +460,7 @@ TEST(String, ConvertEscapedChars) WEE_TEST_STR(NULL, string_convert_escaped_chars (NULL)); WEE_TEST_STR("", string_convert_escaped_chars ("")); + WEE_TEST_STR("", string_convert_escaped_chars ("\\")); WEE_TEST_STR("\"", string_convert_escaped_chars ("\\\"")); WEE_TEST_STR("\\", string_convert_escaped_chars ("\\\\")); WEE_TEST_STR("\a", string_convert_escaped_chars ("\\a"));