Commit 0b64d319 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

wininet: Support ICU_ENCODE_PERCENT, ICU_ENCODE_SPACES_ONLY, and ICU_NO_META.

parent 882977ee
......@@ -1963,6 +1963,32 @@ DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
/***********************************************************************
* convert_url_canonicalization_flags
*
* Helper for InternetCanonicalizeUrl
*
* PARAMS
* dwFlags [I] Flags suitable for InternetCanonicalizeUrl
*
* RETURNS
* Flags suitable for UrlCanonicalize
*/
static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
{
DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
/* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
return dwUrlFlags;
}
/***********************************************************************
* InternetCanonicalizeUrlA (WININET.@)
*
* Escape unsafe characters and spaces
......@@ -1976,43 +2002,16 @@ BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
LPDWORD lpdwBufferLength, DWORD dwFlags)
{
HRESULT hr;
DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
if(dwFlags & ICU_DECODE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_DECODE;
}
if(dwFlags & ICU_ESCAPE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_ESCAPE;
}
if(dwFlags & ICU_BROWSER_MODE)
{
dwURLFlags |= URL_BROWSER_MODE;
dwFlags &= ~ICU_BROWSER_MODE;
}
if(dwFlags & ICU_NO_ENCODE)
{
/* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
dwURLFlags ^= URL_ESCAPE_UNSAFE;
dwFlags &= ~ICU_NO_ENCODE;
}
if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
dwFlags = convert_url_canonicalization_flags(dwFlags);
hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
return (hr == S_OK) ? TRUE : FALSE;
return hr == S_OK;
}
/***********************************************************************
......@@ -2029,43 +2028,16 @@ BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
LPDWORD lpdwBufferLength, DWORD dwFlags)
{
HRESULT hr;
DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
if(dwFlags & ICU_DECODE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_DECODE;
}
if(dwFlags & ICU_ESCAPE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_ESCAPE;
}
if(dwFlags & ICU_BROWSER_MODE)
{
dwURLFlags |= URL_BROWSER_MODE;
dwFlags &= ~ICU_BROWSER_MODE;
}
if(dwFlags & ICU_NO_ENCODE)
{
/* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
dwURLFlags ^= URL_ESCAPE_UNSAFE;
dwFlags &= ~ICU_NO_ENCODE;
}
if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
dwFlags = convert_url_canonicalization_flags(dwFlags);
hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
return (hr == S_OK) ? TRUE : FALSE;
return hr == S_OK;
}
/* #################################################### */
......
......@@ -1098,6 +1098,47 @@ static void InternetCreateUrlA_test(void)
HeapFree(GetProcessHeap(), 0, szUrl);
}
static void InternetCanonicalizeUrl_test(void)
{
char src[] = "http://www.winehq.org/%27/ /./>/#> ";
char dst[64];
DWORD dstlen;
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, 0);
ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
/* despite what MSDN says, ICU_BROWSER_MODE seems to be ignored */
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_BROWSER_MODE);
ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
/* ICU_ESCAPE is supposed to be ignored */
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ESCAPE);
ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_DECODE);
ok(strcmp(dst, "http://www.winehq.org/'/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_PERCENT);
ok(strcmp(dst, "http://www.winehq.org/%2527/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_SPACES_ONLY);
ok(strcmp(dst, "http://www.winehq.org/%27/%20/>/#>") == 0, "Got \"%s\"\n", dst);
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_ENCODE);
ok(strcmp(dst, "http://www.winehq.org/%27/ />/#>") == 0, "Got \"%s\"\n", dst);
dstlen = sizeof(dst);
InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_META);
ok(strcmp(dst, "http://www.winehq.org/%27/%20/./%3E/#>") == 0, "Got \"%s\"\n", dst);
}
START_TEST(url)
{
int i;
......@@ -1113,4 +1154,5 @@ START_TEST(url)
InternetCrackUrl_test();
InternetCrackUrlW_test();
InternetCreateUrlA_test();
InternetCanonicalizeUrl_test();
}
......@@ -421,6 +421,7 @@ BOOLAPI InternetCombineUrlW(LPCWSTR ,LPCWSTR ,LPWSTR ,LPDWORD ,DWORD);
#define ICU_NO_META 0x08000000
#define ICU_ENCODE_SPACES_ONLY 0x04000000
#define ICU_BROWSER_MODE 0x02000000
#define ICU_ENCODE_PERCENT 0x00001000
INTERNETAPI HINTERNET WINAPI InternetOpenA(LPCSTR ,DWORD ,LPCSTR ,LPCSTR ,DWORD);
INTERNETAPI HINTERNET WINAPI InternetOpenW(LPCWSTR ,DWORD ,LPCWSTR ,LPCWSTR ,DWORD);
......
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