From: WanBingjiang Date: Tue, 17 Mar 2026 02:17:15 +0000 (+0800) Subject: mbsalign: add support for SCS escape sequences X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=920e308a9f97deb566d63baf10334976c0568614;p=thirdparty%2Futil-linux.git 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 --- 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