Commit 075f8065 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

shell32: Handle drive letters properly when parsing MyComputer.

Besides PathGetDriveNumber being dangerous and having a completely messed up result with \\?\ prefix, a backslash is not required anymore on newer Windows versions. So e.g. C: should succeed to be parsed. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com>
parent 2b2c09a0
...@@ -151,7 +151,7 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface, ...@@ -151,7 +151,7 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes) DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
{ {
IDesktopFolderImpl *This = impl_from_IShellFolder2(iface); IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
WCHAR szElement[MAX_PATH]; WCHAR c, szElement[MAX_PATH];
LPCWSTR szNext = NULL; LPCWSTR szNext = NULL;
LPITEMIDLIST pidlTemp = NULL; LPITEMIDLIST pidlTemp = NULL;
PARSEDURLW urldata; PARSEDURLW urldata;
...@@ -179,7 +179,8 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface, ...@@ -179,7 +179,8 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
SHCLSIDFromStringW (szElement + 2, &clsid); SHCLSIDFromStringW (szElement + 2, &clsid);
pidlTemp = _ILCreateGuid (PT_GUID, &clsid); pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
} }
else if (PathGetDriveNumberW (lpszDisplayName) >= 0) /* we can't use PathGetDriveNumberW because we can't have the \\?\ prefix */
else if ((c = towupper(lpszDisplayName[0])) >= 'A' && c <= 'Z' && lpszDisplayName[1] == ':')
{ {
/* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */ /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
pidlTemp = _ILCreateMyComputer (); pidlTemp = _ILCreateMyComputer ();
......
...@@ -189,7 +189,7 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface, ...@@ -189,7 +189,7 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface); IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
HRESULT hr = E_INVALIDARG; HRESULT hr = E_INVALIDARG;
LPCWSTR szNext = NULL; LPCWSTR szNext = NULL;
WCHAR szElement[MAX_PATH]; WCHAR c, szElement[MAX_PATH];
LPITEMIDLIST pidlTemp = NULL; LPITEMIDLIST pidlTemp = NULL;
CLSID clsid; CLSID clsid;
...@@ -209,13 +209,17 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface, ...@@ -209,13 +209,17 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
SHCLSIDFromStringW (szElement + 2, &clsid); SHCLSIDFromStringW (szElement + 2, &clsid);
pidlTemp = _ILCreateGuid (PT_GUID, &clsid); pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
} }
/* do we have an absolute path name ? */ /* we can't use PathGetDriveNumberW because we can't have the \\?\ prefix */
else if (PathGetDriveNumberW (lpszDisplayName) >= 0 && else if ((c = towupper(lpszDisplayName[0])) >= 'A' && c <= 'Z' &&
lpszDisplayName[2] == (WCHAR) '\\') lpszDisplayName[1] == ':' &&
(lpszDisplayName[2] == '\\' || lpszDisplayName[2] == '\0'))
{ {
szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH); /* drive letter has to be uppercase to enable PIDL comparison */
/* make drive letter uppercase to enable PIDL comparison */ szElement[0] = c;
szElement[0] = toupper(szElement[0]); szElement[1] = ':';
szElement[2] = '\\';
szElement[3] = '\0';
szNext = &lpszDisplayName[2] + (lpszDisplayName[2] == '\\');
pidlTemp = _ILCreateDrive (szElement); pidlTemp = _ILCreateDrive (szElement);
} }
...@@ -224,7 +228,7 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface, ...@@ -224,7 +228,7 @@ static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
(LPOLESTR) szNext, pchEaten, pdwAttributes); (LPOLESTR) szNext, pchEaten, pdwAttributes);
} }
else else if (pidlTemp)
{ {
if (pdwAttributes && *pdwAttributes) if (pdwAttributes && *pdwAttributes)
SHELL32_GetItemAttributes (&This->IShellFolder2_iface, pidlTemp, pdwAttributes); SHELL32_GetItemAttributes (&This->IShellFolder2_iface, pidlTemp, pdwAttributes);
......
...@@ -85,7 +85,6 @@ static void test_parse_for_my_computer(void) ...@@ -85,7 +85,6 @@ static void test_parse_for_my_computer(void)
pidl = NULL; pidl = NULL;
eaten = 0xdeadbeef; eaten = 0xdeadbeef;
hr = IShellFolder_ParseDisplayName(mycomp, NULL, NULL, path, &eaten, &pidl, NULL); hr = IShellFolder_ParseDisplayName(mycomp, NULL, NULL, path, &eaten, &pidl, NULL);
todo_wine
ok(hr == E_INVALIDARG, "IShellFolder::ParseDisplayName should have failed with E_INVALIDARG, got 0x%08lx\n", hr); ok(hr == E_INVALIDARG, "IShellFolder::ParseDisplayName should have failed with E_INVALIDARG, got 0x%08lx\n", hr);
todo_wine todo_wine
ok(eaten == 0xdeadbeef, "eaten should not have been set to %lu\n", eaten); ok(eaten == 0xdeadbeef, "eaten should not have been set to %lu\n", eaten);
...@@ -101,7 +100,6 @@ static void test_parse_for_my_computer(void) ...@@ -101,7 +100,6 @@ static void test_parse_for_my_computer(void)
"IShellFolder::ParseDisplayName failed with error 0x%lx\n", hr); "IShellFolder::ParseDisplayName failed with error 0x%lx\n", hr);
todo_wine todo_wine
ok(eaten == 0xdeadbeef, "eaten should not have been set to %lu\n", eaten); ok(eaten == 0xdeadbeef, "eaten should not have been set to %lu\n", eaten);
todo_wine
ok(pidl != NULL || broken(!pidl) /* WinXP */, "pidl is NULL\n"); ok(pidl != NULL || broken(!pidl) /* WinXP */, "pidl is NULL\n");
ILFree(pidl); ILFree(pidl);
......
...@@ -199,8 +199,8 @@ static struct ...@@ -199,8 +199,8 @@ static struct
{{'c',':','\\',0}, S_OK}, {{'c',':','\\',0}, S_OK},
{{'c',':','\\','\\',0}, E_INVALIDARG, 1}, {{'c',':','\\','\\',0}, E_INVALIDARG, 1},
{{'c',':','\\','f','a','k','e',0}, 0x80070002}, /* ERROR_FILE_NOT_FOUND */ {{'c',':','\\','f','a','k','e',0}, 0x80070002}, /* ERROR_FILE_NOT_FOUND */
{{'c',':','f','a','k','e',0}, E_INVALIDARG, 1}, {{'c',':','f','a','k','e',0}, E_INVALIDARG},
{{'c',':','/',0}, E_INVALIDARG, 1}, {{'c',':','/',0}, E_INVALIDARG},
{{'c',':','\\','w','i','n','d','o','w','s',0}, S_OK}, {{'c',':','\\','w','i','n','d','o','w','s',0}, S_OK},
{{'c',':','\\','w','i','n','d','o','w','s','\\',0}, S_OK}, {{'c',':','\\','w','i','n','d','o','w','s','\\',0}, S_OK},
{{'c',':','\\','w','i','n','d','o','w','s','\\','.',0}, E_INVALIDARG, 1}, {{'c',':','\\','w','i','n','d','o','w','s','\\','.',0}, E_INVALIDARG, 1},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment