diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c index f3254bc1d32..fc95bf936b7 100644 --- a/dlls/shlwapi/tests/path.c +++ b/dlls/shlwapi/tests/path.c @@ -34,6 +34,27 @@ const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923"; const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923"; const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y"; +typedef struct _TEST_URL_CANONICALIZE { + char *url; + DWORD flags; + HRESULT expectret; + char *expecturl; +} TEST_URL_CANONICALIZE; + +const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = { + {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/"}, + {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, + {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, + {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example"}, +}; + static LPWSTR GetWideString(const char* szString) { LPWSTR wszString = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, @@ -108,8 +129,44 @@ static void test_UrlGetPart(void) test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y"); } +static void test_url_canonicalize(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) +{ + CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; + WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH]; + LPWSTR wszUrl = GetWideString(szUrl); + LPWSTR wszExpectUrl = GetWideString(szExpectUrl); + LPWSTR wszConvertedUrl; + + DWORD dwSize; + + dwSize = INTERNET_MAX_URL_LENGTH; + ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08lx\n", dwExpectReturn); + dwSize = INTERNET_MAX_URL_LENGTH; + ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08lx\n", dwExpectReturn); + + wszConvertedUrl = GetWideString(szReturnUrl); + ok(strcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize!\n"); + FreeWideString(wszConvertedUrl); + + ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl); + + FreeWideString(wszUrl); + FreeWideString(wszExpectUrl); +} + + +static void test_UrlCanonicalize(void) +{ + int i; + for(i=0; i need to backup wk2 */ TRACE("found '/../'\n"); *(wk2-1) = L'\0'; /* set end of string */ @@ -557,7 +557,10 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized, if (mp && (mp >= root)) { /* found valid backup point */ wk2 = mp + 1; - wk1 += 3; + if(*(wk1+2) != L'/') + wk1 += 2; + else + wk1 += 3; } else { /* did not find point, restore '/' */