From 5d1b0d89b402e80d8ffc6cbb8dcdd2df76b834be Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 29 Jul 2006 16:11:31 +0200 Subject: [PATCH] shlwapi: Change file path to URL in UrlCanonicalize. --- dlls/shlwapi/tests/path.c | 7 ++++++- dlls/shlwapi/url.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c index abb13ceacd6..d55d19dba04 100644 --- a/dlls/shlwapi/tests/path.c +++ b/dlls/shlwapi/tests/path.c @@ -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"); diff --git a/dlls/shlwapi/url.c b/dlls/shlwapi/url.c index 47334f65e2c..3c4f28bb8d1 100644 --- a/dlls/shlwapi/url.c +++ b/dlls/shlwapi/url.c @@ -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: