shlwapi: Improved UrlEscapeW implementation.

This commit is contained in:
Piotr Caban 2010-09-05 22:13:47 +02:00 committed by Alexandre Julliard
parent 8b7fae35e4
commit f0bc60324a
2 changed files with 27 additions and 4 deletions

View File

@ -762,10 +762,13 @@ static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, H
static void test_UrlEscape(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");
@ -796,6 +799,14 @@ static void test_UrlEscape(void)
ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
ok(size == 34, "got %d, expected %d\n", size, 34);
if(pUrlEscapeW) {
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));
}
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);

View File

@ -1022,8 +1022,8 @@ HRESULT WINAPI UrlEscapeW(
DWORD slashes = 0;
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
TRACE("(%s %p %p 0x%08x)\n", debugstr_w(pszUrl), pszEscaped,
pcchEscaped, dwFlags);
TRACE("(%p(%s) %p %p 0x%08x)\n", pszUrl, debugstr_w(pszUrl),
pszEscaped, pcchEscaped, dwFlags);
if(!pszUrl || !pcchEscaped)
return E_INVALIDARG;
@ -1034,6 +1034,12 @@ HRESULT WINAPI UrlEscapeW(
URL_ESCAPE_PERCENT))
FIXME("Unimplemented flags: %08x\n", dwFlags);
if(pszUrl == pszEscaped) {
dst = HeapAlloc(GetProcessHeap(), 0, *pcchEscaped*sizeof(WCHAR));
if(!dst)
return E_OUTOFMEMORY;
}
/* fix up flags */
if (dwFlags & URL_ESCAPE_SPACES_ONLY)
/* if SPACES_ONLY specified, reset the other controls */
@ -1150,12 +1156,18 @@ HRESULT WINAPI UrlEscapeW(
if(needed < *pcchEscaped) {
*dst = '\0';
if(pszUrl == pszEscaped)
memcpy(pszEscaped, dst-needed, (needed+1)*sizeof(WCHAR));
ret = S_OK;
} else {
needed++; /* add one for the '\0' */
ret = E_POINTER;
}
*pcchEscaped = needed;
if(pszUrl == pszEscaped)
HeapFree(GetProcessHeap(), 0, dst);
return ret;
}