From 0b64d319c9190bbfaedd6ffd411bc9279f85e2b9 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sun, 29 Jul 2012 23:42:36 -0600 Subject: [PATCH] wininet: Support ICU_ENCODE_PERCENT, ICU_ENCODE_SPACES_ONLY, and ICU_NO_META. --- dlls/wininet/internet.c | 92 ++++++++++++++-------------------------- dlls/wininet/tests/url.c | 42 ++++++++++++++++++ include/wininet.h | 1 + 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 2b659dafec2..9091ce8b614 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -1962,6 +1962,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.@) * @@ -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; } /* #################################################### */ diff --git a/dlls/wininet/tests/url.c b/dlls/wininet/tests/url.c index a391aa61896..8559aae7b54 100644 --- a/dlls/wininet/tests/url.c +++ b/dlls/wininet/tests/url.c @@ -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(); } diff --git a/include/wininet.h b/include/wininet.h index 530a6935eb6..4c479027fd0 100644 --- a/include/wininet.h +++ b/include/wininet.h @@ -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);