-/* $OpenBSD: input.c,v 1.123 2017/06/03 17:43:01 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.124 2017/06/04 09:02:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
switch (option) {
case 0:
case 2:
- screen_set_title(ictx->ctx.s, p);
- server_status_window(ictx->wp->window);
+ if (utf8_isvalid(p)) {
+ screen_set_title(ictx->ctx.s, p);
+ server_status_window(ictx->wp->window);
+ }
break;
case 4:
input_osc_4(ictx->wp, p);
input_osc_11(ictx->wp, p);
break;
case 12:
- if (*p != '?') /* ? is colour request */
+ if (utf8_isvalid(p) && *p != '?') /* ? is colour request */
screen_set_cursor_colour(ictx->ctx.s, p);
break;
case 52:
return;
log_debug("%s: \"%s\"", __func__, ictx->input_buf);
+ if (!utf8_isvalid(ictx->input_buf))
+ return;
screen_set_title(ictx->ctx.s, ictx->input_buf);
server_status_window(ictx->wp->window);
}
return;
log_debug("%s: \"%s\"", __func__, ictx->input_buf);
+ if (!utf8_isvalid(ictx->input_buf))
+ return;
window_set_name(ictx->wp->window, ictx->input_buf);
options_set_number(ictx->wp->window->options, "automatic-rename", 0);
-
server_status_window(ictx->wp->window);
}
-/* $OpenBSD: screen.c,v 1.46 2017/02/08 16:45:18 nicm Exp $ */
+/* $OpenBSD: screen.c,v 1.47 2017/06/04 09:02:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <vis.h>
#include "tmux.h"
screen_set_title(struct screen *s, const char *title)
{
free(s->title);
- s->title = xstrdup(title);
+ utf8_stravis(&s->title, title, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
}
/* Resize screen. */
-/* $OpenBSD: tmux.h,v 1.780 2017/06/04 08:25:57 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.781 2017/06/04 09:02:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
enum utf8_state utf8_append(struct utf8_data *, u_char);
enum utf8_state utf8_combine(const struct utf8_data *, wchar_t *);
enum utf8_state utf8_split(wchar_t, struct utf8_data *);
+int utf8_isvalid(const char *);
int utf8_strvis(char *, const char *, size_t, int);
int utf8_stravis(char **, const char *, int);
char *utf8_sanitize(const char *);
-/* $OpenBSD: utf8.c,v 1.37 2017/05/31 17:56:48 nicm Exp $ */
+/* $OpenBSD: utf8.c,v 1.38 2017/06/04 09:02:36 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
return (len);
}
+/* Does this string contain anything that isn't valid UTF-8? */
+int
+utf8_isvalid(const char *s)
+{
+ struct utf8_data ud;
+ const char *end;
+ enum utf8_state more;
+ size_t i;
+
+ end = s + strlen(s);
+ while (s < end) {
+ if ((more = utf8_open(&ud, *s)) == UTF8_MORE) {
+ while (++s < end && more == UTF8_MORE)
+ more = utf8_append(&ud, *s);
+ if (more == UTF8_DONE)
+ continue;
+ return (0);
+ }
+ if (*s < 0x20 || *s > 0x7e)
+ return (0);
+ s++;
+ }
+ return (1);
+}
+
/*
* Sanitize a string, changing any UTF-8 characters to '_'. Caller should free
* the returned string. Anything not valid printable ASCII or UTF-8 is
-/* $OpenBSD: window.c,v 1.197 2017/05/31 10:15:51 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.198 2017/06/04 09:02:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
#include <time.h>
#include <unistd.h>
#include <util.h>
+#include <vis.h>
#include "tmux.h"
window_set_name(struct window *w, const char *new_name)
{
free(w->name);
- w->name = xstrdup(new_name);
+ utf8_stravis(&w->name, new_name, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
notify_window("window-renamed", w);
}