https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8c7233e01587afde3d7b53...
commit 8c7233e01587afde3d7b53961857dc8a1454a411 Author: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com AuthorDate: Wed Mar 1 19:57:10 2023 +0900 Commit: GitHub noreply@github.com CommitDate: Wed Mar 1 19:57:10 2023 +0900
[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;