From 1c0337dabc5a5fe2c6391411be7537928bb7779b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 7 Sep 2023 13:09:37 +0300 Subject: fixes #3668 (cyrillic letters are allowed in the internal account names) --- src/mir_app/src/proto_opts.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp index 06f2eee4a6..fa1ebf12e7 100644 --- a/src/mir_app/src/proto_opts.cpp +++ b/src/mir_app/src/proto_opts.cpp @@ -859,18 +859,26 @@ bool CAccountFormDlg::OnInitDialog() bool CAccountFormDlg::OnApply() { - wchar_t tszAccName[256]; - m_accName.GetText(tszAccName, _countof(tszAccName)); - rtrimw(tszAccName); - if (tszAccName[0] == 0) { + wchar_t wszAccName[256]; + m_accName.GetText(wszAccName, _countof(wszAccName)); + rtrimw(wszAccName); + if (wszAccName[0] == 0) { MessageBoxW(m_hwnd, TranslateT("Account name must be filled."), TranslateT("Account error"), MB_ICONERROR | MB_OK); return false; } if (m_action == PRAC_ADDED) { - char buf[200]; - m_internalName.GetTextA(buf, _countof(buf)); - if (FindAccountByName(rtrim(buf))) { + wchar_t buf[200]; + m_internalName.GetText(buf, _countof(buf)); + rtrimw(buf); + + for (auto *p = buf; *p; p++) + if (*p < 32 || *p > 127) { + MessageBoxW(m_hwnd, TranslateT("Account name contains invalid symbols, only ASCII chars are allowed."), TranslateT("Account error"), MB_ICONERROR | MB_OK); + return false; + } + + if (FindAccountByName(_T2A(buf))) { MessageBoxW(m_hwnd, TranslateT("Account name has to be unique. Please enter unique name."), TranslateT("Account error"), MB_ICONERROR | MB_OK); return false; } @@ -899,10 +907,10 @@ bool CAccountFormDlg::OnApply() m_internalName.GetTextA(buf, _countof(buf)); rtrim(buf); - m_pa = Proto_CreateAccount(buf, szBaseProto, tszAccName); + m_pa = Proto_CreateAccount(buf, szBaseProto, wszAccName); } else { - replaceStrW(m_pa->tszAccountName, tszAccName); + replaceStrW(m_pa->tszAccountName, wszAccName); WriteDbAccounts(); NotifyEventHooks(hAccListChanged, m_action, (LPARAM)m_pa); -- cgit v1.2.3