From 8c7233e01587afde3d7b53961857dc8a1454a411 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Wed, 1 Mar 2023 19:57:10 +0900 Subject: [PATCH] [NOTEPAD] Fix NOTEPAD_FindTextAt (#5103) The whole-word search of Notepad had a bug around punctuation. For example, the text "Windows" didn't match in the text "MS-DOS,Windows,ReactOS". Use _istalnum instead of _istspace. Fix the position to check. _istalnum matches an alphabet letter or numeric digit. CORE-18837 --- base/applications/notepad/main.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/base/applications/notepad/main.c b/base/applications/notepad/main.c index 52370736318..f4312159731 100644 --- a/base/applications/notepad/main.c +++ b/base/applications/notepad/main.c @@ -109,30 +109,36 @@ static int NOTEPAD_MenuCommand(WPARAM wParam) */ static BOOL -NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition) +NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition) { BOOL bMatches; size_t iTargetLength; + LPCTSTR pchPosition; - if ((!pFindReplace) || (!pszText)) - { + if (!pFindReplace || !pszText) return FALSE; - } iTargetLength = _tcslen(pFindReplace->lpstrFindWhat); + pchPosition = &pszText[dwPosition]; /* Make proper comparison */ if (pFindReplace->Flags & FR_MATCHCASE) - bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength); + bMatches = !_tcsncmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength); else - bMatches = !_tcsnicmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength); + bMatches = !_tcsnicmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength); - if (bMatches && pFindReplace->Flags & FR_WHOLEWORD) + if (bMatches && (pFindReplace->Flags & FR_WHOLEWORD)) { - if ((dwPosition > 0) && !_istspace(pszText[dwPosition-1])) - bMatches = FALSE; - if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1])) - bMatches = FALSE; + if (dwPosition > 0) + { + if (_istalnum(*(pchPosition - 1)) || *(pchPosition - 1) == _T('_')) + bMatches = FALSE; + } + if ((INT)dwPosition + iTargetLength < iTextLength) + { + if (_istalnum(pchPosition[iTargetLength]) || pchPosition[iTargetLength] == _T('_')) + bMatches = FALSE; + } } return bMatches;