shlwapi: Change file path to URL in UrlCanonicalize.

This commit is contained in:
Jacek Caban 2006-07-29 16:11:31 +02:00 committed by Alexandre Julliard
parent 5674260b6d
commit 5d1b0d89b4
2 changed files with 21 additions and 2 deletions

View File

@ -77,6 +77,11 @@ const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
{"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar"},
{"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about"},
{"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about"},
{"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"},
{"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"},
{"c:dir\\file", 0, S_OK, "file:///c:dir/file"},
{"A", 0, S_OK, "A"},
{"", 0, S_OK, ""}
};
typedef struct _TEST_URL_ESCAPE {
@ -429,7 +434,7 @@ static void test_url_canonicalize(const char *szUrl, DWORD dwFlags, HRESULT dwEx
dwSize = INTERNET_MAX_URL_LENGTH;
ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n");
ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08lx\n", dwExpectReturn);
ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08lx Expected %s, but got %s\n", dwFlags, szExpectUrl, szReturnUrl);
ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08lx Expected \"%s\", but got \"%s\"\n", dwFlags, szExpectUrl, szReturnUrl);
dwSize = INTERNET_MAX_URL_LENGTH;
ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n");

View File

@ -340,8 +340,13 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
if(!pszUrl || !pszCanonicalized || !pcchCanonicalized)
return E_INVALIDARG;
if(!*pszUrl) {
*pszCanonicalized = 0;
return S_OK;
}
nByteLen = (lstrlenW(pszUrl) + 1) * sizeof(WCHAR); /* length in bytes */
lpszUrlCpy = HeapAlloc(GetProcessHeap(), 0, nByteLen);
lpszUrlCpy = HeapAlloc(GetProcessHeap(), 0, INTERNET_MAX_URL_LENGTH);
if((dwFlags & URL_FILE_USE_PATHURL) && nByteLen >= sizeof(wszFile)
&& !memcmp(wszFile, pszUrl, sizeof(wszFile)))
@ -361,6 +366,15 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
wk1 = (LPWSTR)pszUrl;
wk2 = lpszUrlCpy;
state = 0;
if(pszUrl[1] == ':') { /* Assume path */
static const WCHAR wszFilePrefix[] = {'f','i','l','e',':','/','/','/'};
memcpy(wk2, wszFilePrefix, sizeof(wszFilePrefix));
wk2 += sizeof(wszFilePrefix)/sizeof(WCHAR);
state = 5;
}
while (*wk1) {
switch (state) {
case 0: