From a28342be99eb4557f576ac89efe486dce95c7f2b Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Mon, 14 Nov 2022 20:10:02 -0500 Subject: [PATCH] Fix password handling in _InputBox$ on Windows We were incorrectly treating the empty string and NULL the same and using a password dialog for both. It now has the correct behavior of displaying the password when provided the empty string, but just displaying a blank input box when provided NULL. --- internal/c/parts/gui/tinyfiledialogs.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/c/parts/gui/tinyfiledialogs.c b/internal/c/parts/gui/tinyfiledialogs.c index 3f13f7879..f607a8a0f 100644 --- a/internal/c/parts/gui/tinyfiledialogs.c +++ b/internal/c/parts/gui/tinyfiledialogs.c @@ -1299,6 +1299,18 @@ static LRESULT displayInputBox(HINSTANCE hinst, HWND hwndOwner, const wchar_t *t LPWSTR lpwsz; LRESULT ret; int nchar; + int isPassword = 0; + + if (!title) + title = L""; + + if (!lpszMessage) + lpszMessage = L""; + + if (!defaultText) { + isPassword = 1; + defaultText = L""; + } // The extra 500 accounts for the default button text, alignment padding, and a few other small things hgbl = GlobalAlloc(GMEM_ZEROINIT, sizeof(DLGTEMPLATE) @@ -1343,7 +1355,7 @@ static LRESULT displayInputBox(HINSTANCE hinst, HWND hwndOwner, const wchar_t *t lpdit->id = ID_TEXT; // Text identifier lpdit->style = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL | ES_LEFT; - if (wcslen(defaultText) == 0) + if (isPassword) lpdit->style |= ES_PASSWORD; lpw = (LPWORD)(lpdit + 1); @@ -1431,10 +1443,6 @@ wchar_t * tinyfd_inputBoxW( memset(dialogContents, 0, sizeof(dialogContents)); - aTitle = aTitle? aTitle: L""; - aMessage = aMessage? aMessage: L""; - aDefaultInput = aDefaultInput? aDefaultInput: L""; - displayInputBox(GetModuleHandle(NULL), GetDialogWindow(), aTitle, aMessage, aDefaultInput); mbstowcs(lBuff, dialogContents, MAX_PATH_OR_CMD);