static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) { HRESULT hr; CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH]; LPWSTR wszUrl1 = GetWideString(szUrl1); LPWSTR wszUrl2 = GetWideString(szUrl2); LPWSTR wszExpectUrl = GetWideString(szExpectUrl); LPWSTR wszConvertedUrl; DWORD dwSize; DWORD dwExpectLen = lstrlen(szExpectUrl); hr = UrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags); ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG); dwSize = 0; hr = UrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags); ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER); ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1); dwSize--; hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags); ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER); ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1); hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags); ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn); ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen); if(SUCCEEDED(hr)) { ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl); } dwSize = 0; hr = UrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags); ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER); ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1); dwSize--; hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags); ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER); ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1); hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags); ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn); ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen); if(SUCCEEDED(hr)) { wszConvertedUrl = GetWideString(szReturnUrl); ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n"); FreeWideString(wszConvertedUrl); } FreeWideString(wszUrl1); FreeWideString(wszUrl2); FreeWideString(wszExpectUrl); }
/************************************************************************** * CoInternetCombineUrl (URLMON.@) */ HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved) { IInternetProtocolInfo *protocol_info; DWORD size = cchResult; HRESULT hres; TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl), debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved); protocol_info = get_protocol_info(pwzBaseUrl); if(protocol_info) { hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl, dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved); IInternetProtocolInfo_Release(protocol_info); if(SUCCEEDED(hres)) return hres; } hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags); if(pcchResult) *pcchResult = size; return hres; }
HRESULT UrlCombineUnescape(LPCWSTR pszBase, LPCWSTR pszRelative, LPWSTR pszCombined, LPDWORD pcchCombined, DWORD dwFlags) { HRESULT hr = S_OK; DWORD dwSize; LPWSTR pwzCombined = NULL; LPWSTR pwzFileCombined = NULL; pwzCombined = NEW(WCHAR[MAX_URL_LENGTH]); if (!pwzCombined) { hr = E_OUTOFMEMORY; goto Exit; } // If we're just combining an absolute file path to an relative file // path, do this by concatenating the strings, and canonicalizing it. // This avoids UrlCombine randomness where you could end up with // a partially escaped (and partially unescaped) resulting URL! if (!PathIsURLW(pszBase) && PathIsRelativeWrap(pszRelative)) { pwzFileCombined = NEW(WCHAR[MAX_URL_LENGTH]); if (!pwzFileCombined) { hr = E_OUTOFMEMORY; goto Exit; } wnsprintfW(pwzFileCombined, MAX_URL_LENGTH, L"%ws%ws", pszBase, pszRelative); hr = UrlCanonicalizeUnescape(pwzFileCombined, pszCombined, pcchCombined, 0); goto Exit; } else { dwSize = MAX_URL_LENGTH; hr = UrlCombineW(pszBase, pszRelative, pwzCombined, &dwSize, dwFlags); if (FAILED(hr)) { goto Exit; } } // Don't unescape if the relative part was already an URL because // URLs wouldn't have been escaped during the UrlCombined. if (UrlIsW(pwzCombined, URLIS_FILEURL)) { hr = UrlUnescapeW(pwzCombined, pszCombined, pcchCombined, 0); if (FAILED(hr)) { goto Exit; } } else { if (*pcchCombined >= dwSize) { lstrcpyW(pszCombined, pwzCombined); } *pcchCombined = dwSize; } Exit: SAFEDELETEARRAY(pwzCombined); SAFEDELETEARRAY(pwzFileCombined); return hr; }