[git commit] lineedit: fix unicode characters in prompt

Denys Vlasenko vda.linux at googlemail.com
Sat Nov 21 16:34:42 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=9bf4499dd7c72db7636555ec386804540a3266fe
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
parse_and_put_prompt                                 779     823     +44

Signed-off-by: Audun-Marius Gangstø <audun at gangsto.org>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/lineedit.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index e40a72064..a3b798e3f 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2029,10 +2029,17 @@ static void parse_and_put_prompt(const char *prmt_ptr)
 			if (c == '\n')
 				cmdedit_prmt_len = 0;
 			else if (flg_not_length != ']') {
-#if 0 /*ENABLE_UNICODE_SUPPORT*/
-/* Won't work, pbuf is one BYTE string here instead of an one Unicode char string. */
-/* FIXME */
-				cmdedit_prmt_len += unicode_strwidth(pbuf);
+#if ENABLE_UNICODE_SUPPORT
+				if (n == 1) {
+					/* Only count single-byte characters and the first of multi-byte characters */
+					if ((unsigned char)*pbuf < 0x80  /* single byte character */
+					 || (unsigned char)*pbuf >= 0xc0 /* first of multi-byte characters */
+					) {
+						cmdedit_prmt_len += n;
+					}
+				} else {
+					cmdedit_prmt_len += unicode_strwidth(pbuf);
+				}
 #else
 				cmdedit_prmt_len += n;
 #endif


More information about the busybox-cvs mailing list