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,26 +862,68 @@ 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) {
WCHAR wc;
for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
CHAR ret_url[INTERNET_MAX_URL_LENGTH];
size = sizeof(overwrite)/sizeof(WCHAR);
ret = pUrlEscapeW(overwrite, overwrite, &size, URL_ESCAPE_SPACES_ONLY);
ok(ret == S_OK, "got %x, expected S_OK\n", ret);
ok(size == 9, "got %d, expected 9\n", size);
ok(!lstrcmpW(overwrite, out), "got %s, expected %s\n", wine_dbgstr_w(overwrite), wine_dbgstr_w(out));
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);
}
}
size = 1;
wc = 127;
ret = pUrlEscapeW(overwrite, &wc, &size, URL_ESCAPE_SPACES_ONLY);
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);
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;
}
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);
size = sizeof(overwrite)/sizeof(WCHAR);
ret = pUrlEscapeW(overwrite, overwrite, &size, URL_ESCAPE_SPACES_ONLY);
ok(ret == S_OK, "got %x, expected S_OK\n", ret);
ok(size == 9, "got %d, expected 9\n", size);
ok(!lstrcmpW(overwrite, out), "got %s, expected %s\n", wine_dbgstr_w(overwrite), wine_dbgstr_w(out));
size = 1;
wc = 127;
ret = pUrlEscapeW(overwrite, &wc, &size, URL_ESCAPE_SPACES_ONLY);
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++) {
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,57 +986,43 @@ 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 '<':
case '>':
case '\"':
case '{':
case '}':
case '|':
case '\\':
case '^':
case ']':
case '[':
case '`':
case '&':
return TRUE;
case '/':
if (int_flags & WINE_URL_ESCAPE_SLASH) return TRUE;
return FALSE;
case '?':
if (int_flags & WINE_URL_ESCAPE_QUESTION) return TRUE;
return FALSE;
case '#':
if (int_flags & WINE_URL_ESCAPE_HASH) return TRUE;
return FALSE;
default:
return FALSE;
}
switch (ch) {
case ' ':
case '<':
case '>':
case '\"':
case '{':
case '}':
case '|':
case '\\':
case '^':
case ']':
case '[':
case '`':
case '&':
return TRUE;
case '/':
return !!(int_flags & WINE_URL_ESCAPE_SLASH);
case '?':
return !!(int_flags & WINE_URL_ESCAPE_QUESTION);
case '#':
return !!(int_flags & WINE_URL_ESCAPE_HASH);
default:
return FALSE;
}
}