Fix UrlCanonicalize and add regression test.
This commit is contained in:
parent
2ab690bcbb
commit
8ac9773e3b
|
@ -34,6 +34,27 @@ const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
|
|||
const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
|
||||
const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
|
||||
|
||||
typedef struct _TEST_URL_CANONICALIZE {
|
||||
char *url;
|
||||
DWORD flags;
|
||||
HRESULT expectret;
|
||||
char *expecturl;
|
||||
} TEST_URL_CANONICALIZE;
|
||||
|
||||
const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
|
||||
{"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests"},
|
||||
{"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/"},
|
||||
{"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/"},
|
||||
{"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/"},
|
||||
{"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/"},
|
||||
{"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/"},
|
||||
{"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"},
|
||||
{"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"},
|
||||
{"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example"},
|
||||
{"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example"},
|
||||
{"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example"},
|
||||
};
|
||||
|
||||
static LPWSTR GetWideString(const char* szString)
|
||||
{
|
||||
LPWSTR wszString = (LPWSTR) HeapAlloc(GetProcessHeap(), 0,
|
||||
|
@ -108,8 +129,44 @@ static void test_UrlGetPart(void)
|
|||
test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
|
||||
}
|
||||
|
||||
static void test_url_canonicalize(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
|
||||
{
|
||||
CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
|
||||
WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
|
||||
LPWSTR wszUrl = GetWideString(szUrl);
|
||||
LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
|
||||
LPWSTR wszConvertedUrl;
|
||||
|
||||
DWORD dwSize;
|
||||
|
||||
dwSize = INTERNET_MAX_URL_LENGTH;
|
||||
ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08lx\n", dwExpectReturn);
|
||||
dwSize = INTERNET_MAX_URL_LENGTH;
|
||||
ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08lx\n", dwExpectReturn);
|
||||
|
||||
wszConvertedUrl = GetWideString(szReturnUrl);
|
||||
ok(strcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize!\n");
|
||||
FreeWideString(wszConvertedUrl);
|
||||
|
||||
ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
|
||||
|
||||
FreeWideString(wszUrl);
|
||||
FreeWideString(wszExpectUrl);
|
||||
}
|
||||
|
||||
|
||||
static void test_UrlCanonicalize(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
|
||||
test_url_canonicalize(TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
|
||||
TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl);
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(path)
|
||||
{
|
||||
test_UrlHash();
|
||||
test_UrlGetPart();
|
||||
test_UrlCanonicalize();
|
||||
}
|
||||
|
|
|
@ -514,8 +514,8 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
|
|||
wk2 += strlenW(wk2);
|
||||
break;
|
||||
case 4:
|
||||
if (!isalnumW(*wk1) && (*wk1 != L'-')) {state = 3; break;}
|
||||
while(isalnumW(*wk1) || (*wk1 == L'-')) *wk2++ = *wk1++;
|
||||
if (!isalnumW(*wk1) && (*wk1 != L'-') && (*wk1 != L'.')) {state = 3; break;}
|
||||
while(isalnumW(*wk1) || (*wk1 == L'-') || (*wk1 == L'.')) *wk2++ = *wk1++;
|
||||
state = 5;
|
||||
break;
|
||||
case 5:
|
||||
|
@ -549,7 +549,7 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
|
|||
else if (*(wk1+1) == L'.') {
|
||||
/* found /.. look for next / */
|
||||
TRACE("found '/..'\n");
|
||||
if (*(wk1+2) == L'/') {
|
||||
if (*(wk1+2) == L'/' || *(wk1+2) == L'?' || *(wk1+2) == L'#' || *(wk1+2) == 0) {
|
||||
/* case /../ -> need to backup wk2 */
|
||||
TRACE("found '/../'\n");
|
||||
*(wk2-1) = L'\0'; /* set end of string */
|
||||
|
@ -557,7 +557,10 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
|
|||
if (mp && (mp >= root)) {
|
||||
/* found valid backup point */
|
||||
wk2 = mp + 1;
|
||||
wk1 += 3;
|
||||
if(*(wk1+2) != L'/')
|
||||
wk1 += 2;
|
||||
else
|
||||
wk1 += 3;
|
||||
}
|
||||
else {
|
||||
/* did not find point, restore '/' */
|
||||
|
|
Loading…
Reference in New Issue