From 920e308a9f97deb566d63baf10334976c0568614 Mon Sep 17 00:00:00 2001 From: WanBingjiang Date: Tue, 17 Mar 2026 10:17:15 +0800 Subject: [PATCH] mbsalign: add support for SCS escape sequences Add handling for SCS (Select Character Set) escape sequences: \e(X, \e)X, \e*X, \e+X. These sequences are now properly skipped when calculating string width. Addresses: https://github.com/util-linux/util-linux/issues/4121 Signed-off-by: WanBingjiang --- lib/mbsalign.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mbsalign.c b/lib/mbsalign.c index f94866b8b..97627537f 100644 --- a/lib/mbsalign.c +++ b/lib/mbsalign.c @@ -53,6 +53,12 @@ size_t mbs_nwidth(const char *buf, size_t bufsz) if (*e == 'm') p = e + 1; } + /* try detect SCS sequences "\e(X", "\e)X", "\e*X", "\e+X" and skip on success */ + else if (*p && (*p == '(' || *p == ')' || *p == '*' || *p == '+')) { + p++; /* skip the SCS introducer */ + if (p <= last) + p++; /* skip the character */ + } continue; } #ifdef HAVE_WIDECHAR -- 2.47.3