From 635a4eac05f10582ddbba09b329695aa81a6e1cc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 15 Sep 2023 16:00:43 +1000 Subject: [PATCH] Fix delete key setting a control character in wmEvent::utf8_buf The check for control characters didn't account for delete (127). This wasn't noticeable in most cases as delete is mapped to delete text. Pressing Shift-Delete would enter 127 control character in the text-editor, 3D text & Python console. This happened X11 & Wayland, I didn't check other platforms. --- intern/ghost/intern/GHOST_SystemX11.cc | 7 +++---- source/blender/windowmanager/intern/wm_event_system.cc | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemX11.cc b/intern/ghost/intern/GHOST_SystemX11.cc index de81a9ddf8f..567fe3b228e 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cc +++ b/intern/ghost/intern/GHOST_SystemX11.cc @@ -1108,10 +1108,9 @@ void GHOST_SystemX11::processEvent(XEvent *xe) } if (ELEM(status, XLookupChars, XLookupBoth)) { - if (uchar(utf8_buf[0]) >= 32) { /* not an ascii control character */ - /* do nothing for now, this is valid utf8 */ - } - else { + /* Check for ASCII control characters. + * Inline `iscntrl` because the users locale must not change behavior. */ + if ((utf8_buf[0] < 32 && utf8_buf[0] > 0) || (utf8_buf[0] == 127)) { utf8_buf[0] = '\0'; } } diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 4c17e4590c4..4ecb715a260 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -5670,7 +5670,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, event.utf8_buf[0] = '\0'; } else { - if (event.utf8_buf[0] < 32 && event.utf8_buf[0] > 0) { + /* Check for ASCII control characters. + * Inline `iscntrl` because the users locale must not change behavior. */ + if ((event.utf8_buf[0] < 32 && event.utf8_buf[0] > 0) || (event.utf8_buf[0] == 127)) { event.utf8_buf[0] = '\0'; } }