shlwapi: Fix UrlEscapeW() for non-ASCII range.

This commit is contained in:
Nikolay Sivov 2014-04-18 01:39:13 +04:00 committed by Alexandre Julliard
parent 389992fdfa
commit 462b2feb35
2 changed files with 97 additions and 97 deletions

View File

@ -297,7 +297,9 @@ static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
{"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
{"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
{"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
{"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
{"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"},
{"ftp\x1f\1end/", 0, 0, S_OK, "ftp%1F%01end/"}
};
/* ################ */
@ -779,34 +781,6 @@ static void test_UrlGetPart(void)
}
/* ########################### */
static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
{
CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
DWORD dwEscaped;
WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
WCHAR *urlW, *expected_urlW;
dwEscaped=INTERNET_MAX_URL_LENGTH;
ok(pUrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn,
"UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
if (pUrlEscapeW) {
dwEscaped = INTERNET_MAX_URL_LENGTH;
urlW = GetWideString(szUrl);
expected_urlW = GetWideString(szExpectUrl);
ok(pUrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn,
"UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
ok(lstrcmpW(ret_urlW, expected_urlW)==0,
"Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
szExpectUrl, szReturnUrl, szUrl, dwFlags);
FreeWideString(urlW);
FreeWideString(expected_urlW);
}
}
static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
{
CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
@ -850,18 +824,15 @@ static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, H
}
static void test_UrlEscape(void)
static void test_UrlEscapeA(void)
{
static const WCHAR out[] = { 'f','o','o','%','2','0','b','a','r',0 };
DWORD size = 0;
HRESULT ret;
unsigned int i;
char empty_string[] = "";
WCHAR overwrite[] = { 'f','o','o',' ','b','a','r',0,0,0 };
if (!pUrlEscapeA) {
win_skip("UrlEscapeA noz found\n");
win_skip("UrlEscapeA not found\n");
return;
}
@ -891,8 +862,34 @@ static void test_UrlEscape(void)
ok(size == 34, "got %d, expected %d\n", size, 34);
ok(empty_string[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string[0]);
if(pUrlEscapeW) {
for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
CHAR ret_url[INTERNET_MAX_URL_LENGTH];
size = INTERNET_MAX_URL_LENGTH;
ret = pUrlEscapeA(TEST_ESCAPE[i].url, ret_url, &size, TEST_ESCAPE[i].flags);
ok(ret == TEST_ESCAPE[i].expectret, "UrlEscapeA returned 0x%08x instead of 0x%08x for \"%s\"\n",
ret, TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].url);
ok(!strcmp(ret_url, TEST_ESCAPE[i].expecturl), "Expected \"%s\", but got \"%s\" for \"%s\"\n",
TEST_ESCAPE[i].expecturl, ret_url, TEST_ESCAPE[i].url);
}
}
static void test_UrlEscapeW(void)
{
static const WCHAR naW[] = {'f','t','p',31,255,250,0x2122,'e','n','d','/',0};
static const WCHAR naescapedW[] = {'f','t','p','%','1','F','%','F','F','%','F','A',0x2122,'e','n','d','/',0};
static const WCHAR out[] = {'f','o','o','%','2','0','b','a','r',0};
WCHAR overwrite[] = {'f','o','o',' ','b','a','r',0,0,0};
WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
DWORD size = 0;
HRESULT ret;
WCHAR wc;
int i;
if (!pUrlEscapeW) {
win_skip("UrlEscapeW not found\n");
return;
}
size = sizeof(overwrite)/sizeof(WCHAR);
ret = pUrlEscapeW(overwrite, overwrite, &size, URL_ESCAPE_SPACES_ONLY);
@ -906,11 +903,27 @@ static void test_UrlEscape(void)
ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
ok(size == 10, "got %d, expected 10\n", size);
ok(wc == 127, "String has changed, wc = %d\n", wc);
}
/* non-ASCII range */
size = sizeof(ret_urlW)/sizeof(WCHAR);
ret = pUrlEscapeW(naW, ret_urlW, &size, 0);
ok(ret == S_OK, "got %x, expected S_OK\n", ret);
ok(!lstrcmpW(naescapedW, ret_urlW), "got %s, expected %s\n", wine_dbgstr_w(ret_urlW), wine_dbgstr_w(naescapedW));
for (i = 0; i < sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
WCHAR *urlW, *expected_urlW;
size = INTERNET_MAX_URL_LENGTH;
urlW = GetWideString(TEST_ESCAPE[i].url);
expected_urlW = GetWideString(TEST_ESCAPE[i].expecturl);
ret = pUrlEscapeW(urlW, ret_urlW, &size, TEST_ESCAPE[i].flags);
ok(ret == TEST_ESCAPE[i].expectret, "UrlEscapeW returned 0x%08x instead of 0x%08x for %s\n",
ret, TEST_ESCAPE[i].expectret, wine_dbgstr_w(urlW));
ok(!lstrcmpW(ret_urlW, expected_urlW), "Expected %s, but got %s for %s flags %08x\n",
wine_dbgstr_w(expected_urlW), wine_dbgstr_w(ret_urlW), wine_dbgstr_w(urlW), TEST_ESCAPE[i].flags);
FreeWideString(urlW);
FreeWideString(expected_urlW);
}
}
@ -1548,7 +1561,8 @@ START_TEST(url)
test_UrlGetPart();
test_UrlCanonicalizeA();
test_UrlCanonicalizeW();
test_UrlEscape();
test_UrlEscapeA();
test_UrlEscapeW();
test_UrlCombine();
test_UrlCreateFromPath();
test_UrlIs();

View File

@ -986,26 +986,20 @@ HRESULT WINAPI UrlEscapeA(
#define WINE_URL_STOP_ON_HASH 0x20
#define WINE_URL_STOP_ON_QUESTION 0x40
static inline BOOL URL_NeedEscapeW(WCHAR ch, DWORD dwFlags, DWORD int_flags)
static inline BOOL URL_NeedEscapeW(WCHAR ch, DWORD flags, DWORD int_flags)
{
if (flags & URL_ESCAPE_SPACES_ONLY)
return ch == ' ';
if ((flags & URL_ESCAPE_PERCENT) && (ch == '%'))
return TRUE;
if (ch <= 31 || (ch >= 127 && ch <= 255) )
return TRUE;
if (isalnumW(ch))
return FALSE;
if(dwFlags & URL_ESCAPE_SPACES_ONLY) {
if(ch == ' ')
return TRUE;
else
return FALSE;
}
if ((dwFlags & URL_ESCAPE_PERCENT) && (ch == '%'))
return TRUE;
if (ch <= 31 || ch >= 127)
return TRUE;
else {
switch (ch) {
case ' ':
case '<':
@ -1021,24 +1015,16 @@ static inline BOOL URL_NeedEscapeW(WCHAR ch, DWORD dwFlags, DWORD int_flags)
case '`':
case '&':
return TRUE;
case '/':
if (int_flags & WINE_URL_ESCAPE_SLASH) return TRUE;
return FALSE;
return !!(int_flags & WINE_URL_ESCAPE_SLASH);
case '?':
if (int_flags & WINE_URL_ESCAPE_QUESTION) return TRUE;
return FALSE;
return !!(int_flags & WINE_URL_ESCAPE_QUESTION);
case '#':
if (int_flags & WINE_URL_ESCAPE_HASH) return TRUE;
return FALSE;
return !!(int_flags & WINE_URL_ESCAPE_HASH);
default:
return FALSE;
}
}
}
/*************************************************************************