Skip to content

Commit

Permalink
Wayland: Pass valid UTF-8 as title
Browse files Browse the repository at this point in the history
When stripping CSI sequences from the title, dont mutilate interleaved
multi-byte UTF-8 sequences.

Fixes #8067
  • Loading branch information
kovidgoyal committed Nov 24, 2024
1 parent e625f0a commit ebb733b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
13 changes: 10 additions & 3 deletions kitty/glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -71,18 +72,24 @@ 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; }
else *(dest++) = ch;
} 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;
}
}
Expand Down

0 comments on commit ebb733b

Please sign in to comment.