comdlg32: Correctly handle filters with invalid extensions in Save As dialogs.

oldstable
Alex Henrie 2012-01-24 14:34:43 -07:00 committed by Alexandre Julliard
parent 02b12e1117
commit f0b274bada
2 changed files with 15 additions and 11 deletions

View File

@ -2549,24 +2549,27 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
if (lpstrFilter != (LPWSTR)CB_ERR) /* control is not empty */
{
WCHAR* filterAtSemicolon;
filterExt = HeapAlloc(GetProcessHeap(), 0, lstrlenW(lpstrFilter) * sizeof(WCHAR) + sizeof(WCHAR));
WCHAR* filterSearchIndex;
filterExt = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(lpstrFilter) + 1) * sizeof(WCHAR));
strcpyW(filterExt, lpstrFilter);
/* if a semicolon-separated list of file extensions was given, do not include the
semicolon or anything after it in the extension.
example: if filterExt was "*.abc;*.def", it will become "*.abc" */
filterAtSemicolon = strchrW(filterExt, ';');
if (filterAtSemicolon)
filterSearchIndex = strchrW(filterExt, ';');
if (filterSearchIndex)
{
filterAtSemicolon[0] = '\0';
filterSearchIndex[0] = '\0';
}
/* strip the * or anything else from the extension, "*.abc" becomes "abc" */
strcpyW(filterExt, PathFindExtensionW(filterExt) + 1);
/* if the extension contains a glob, ignore it */
if (strchrW(filterExt, '*') || strchrW(filterExt, '?'))
/* if the extension is invalid or contains a glob, ignore it */
filterSearchIndex = PathFindExtensionW(filterExt);
if (*filterSearchIndex++ && !strchrW(filterSearchIndex, '*') && !strchrW(filterSearchIndex, '?'))
{
strcpyW(filterExt, filterSearchIndex);
}
else
{
HeapFree(GetProcessHeap(), 0, filterExt);
filterExt = NULL;
@ -2576,7 +2579,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
if (!filterExt)
{
/* use the default file extension */
filterExt = HeapAlloc(GetProcessHeap(), 0, lstrlenW(fodInfos->defext) * sizeof(WCHAR) + sizeof(WCHAR));
filterExt = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(fodInfos->defext) + 1) * sizeof(WCHAR));
strcpyW(filterExt, fodInfos->defext);
}
@ -2585,7 +2588,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
/* Attach the dot*/
lstrcatW(lpstrPathAndFile, szwDot);
/* Attach the extension */
lstrcatW(lpstrPathAndFile, filterExt );
lstrcatW(lpstrPathAndFile, filterExt);
}
HeapFree(GetProcessHeap(), 0, filterExt);

View File

@ -1086,6 +1086,7 @@ static void test_extension(void)
"TestFilter (*.pt*;*.abc)\0*.pt*;*.abc\0",
"TestFilter (*.ab?)\0*.ab?\0",
"TestFilter (*.*)\0*.*\0",
"TestFilter (*sav)\0*sav\0",
NULL /* is a test, not an endmark! */
};