diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index 751aa2ef498..550f3a052f9 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -2156,11 +2156,25 @@ static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile { IShellLinkImpl *This = impl_from_IShellLinkW(iface); WCHAR buffer[MAX_PATH]; - LPWSTR fname; + LPWSTR fname, unquoted = NULL; HRESULT hr = S_OK; + UINT len; TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile)); + /* quotes at the ends of the string are stripped */ + len = lstrlenW(pszFile); + if (pszFile[0] == '"' && pszFile[len-1] == '"') + { + unquoted = strdupW(pszFile); + PathUnquoteSpacesW(unquoted); + pszFile = unquoted; + } + + /* any other quote marks are invalid */ + if (strchrW(pszFile, '"')) + return S_FALSE; + HeapFree(GetProcessHeap(), 0, This->sPath); This->sPath = NULL; @@ -2191,6 +2205,7 @@ static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile lstrcpyW(This->sPath, buffer); } This->bDirty = TRUE; + HeapFree(GetProcessHeap(), 0, unquoted); return hr; } diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c index a6cba360287..aaf02836036 100644 --- a/dlls/shell32/tests/shelllink.c +++ b/dlls/shell32/tests/shelllink.c @@ -216,6 +216,29 @@ static void test_get_set(void) ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer); } + /* test path with quotes */ + r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\""); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + + r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH); + ok(r==S_OK, "GetPath failed (0x%08lx)\n", r); + ok(!lstrcmp(buffer, "C:\\nonexistent\\file"), "case doesn't match\n"); + + r = IShellLinkA_SetPath(sl, "\"c:\\foo"); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + + r = IShellLinkA_SetPath(sl, "\"\"c:\\foo"); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + + r = IShellLinkA_SetPath(sl, "c:\\foo\""); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + + r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\""); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + + r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\""); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); + /* Test Getting / Setting the arguments */ strcpy(buffer,"garbage"); r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));