Fix text editor auto-close potentially auto-closing non-brackets

Entering non ascii characters would truncate the code-point to char
when passing it to text_closing_character_pair_get(), which could then
match bracket values. Resolve by checking the characters are ascii.
This commit is contained in:
Campbell Barton
2023-09-17 17:17:33 +10:00
parent 0464b9fc58
commit b9124d8a85

View File

@@ -3603,7 +3603,8 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (U.text_flag & USER_TEXT_EDIT_AUTO_CLOSE) {
auto_close_char = BLI_str_utf8_as_unicode(str);
if (txt_has_sel(st->text) && text_closing_character_pair_get(auto_close_char) != 0 &&
if (txt_has_sel(st->text) && isascii(auto_close_char) &&
text_closing_character_pair_get(auto_close_char) != 0 &&
!text_span_is_blank(st->text->sell, st->text->selc, st->text->curl, st->text->curc))
{
auto_close_select.sell = st->text->sell;
@@ -3635,7 +3636,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ret = text_insert_exec(C, op);
if ((ret == OPERATOR_FINISHED) && (auto_close_char != 0)) {
if ((ret == OPERATOR_FINISHED) && (auto_close_char != 0) && isascii(auto_close_char)) {
const uint auto_close_match = text_closing_character_pair_get(auto_close_char);
if (auto_close_match != 0) {
/* If there was a selection, move cursor to the end of it. */