Wayland: Pass valid UTF-8 as title

When stripping CSI sequences from the title, dont mutilate interleaved
multi-byte UTF-8 sequences.

Fixes #8067
This commit is contained in:
Kovid Goyal 2024-11-24 09:06:46 +05:30
parent e625f0aa02
commit ebb733bad0
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 3 deletions

View file

@ -95,6 +95,8 @@ Detailed list of changes
- clipboard kitten: Fix a bug causing kitten to hang in filter mode when input data size is not divisible by 3 and larger than 8KB (:iss:`8059`)
- Wayland: Fix an abort when a client program tries to set an invalid title containing interleaved escape codes and UTF-8 multi-byte characters (:iss:`8067`)
0.37.0 [2024-10-30]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -8,6 +8,7 @@
#include "cleanup.h"
#include "monotonic.h"
#include "charsets.h"
#include "control-codes.h"
#include <structmember.h>
#include "glfw-wrapper.h"
#include "gl.h"
@ -71,7 +72,7 @@ strip_csi_(const char *title, char *buf, size_t bufsz) {
*dest = 0; *last = 0;
for (; *title && dest < last; title++) {
const char ch = *title;
const unsigned char ch = *title;
switch (state) {
case NORMAL: {
if (ch == 0x1b) { state = IN_ESC; }
@ -79,10 +80,16 @@ strip_csi_(const char *title, char *buf, size_t bufsz) {
} break;
case IN_ESC: {
if (ch == '[') { state = IN_CSI; }
else { state = NORMAL; }
else {
if (ch >= ' ' && ch != DEL) *(dest++) = ch;
state = NORMAL;
}
} break;
case IN_CSI: {
if (!(('0' <= ch && ch <= '9') || ch == ';' || ch == ':')) state = NORMAL;
if (!(('0' <= ch && ch <= '9') || ch == ';' || ch == ':')) {
if (ch >= ' ' && ch != DEL) *(dest++) = ch;
state = NORMAL;
}
} break;
}
}