From 366fc247fcc27a4208d6e8ec081138726462538d Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Tue, 14 Mar 2006 14:35:37 +0000 Subject: [PATCH] wininet: Make InternetCrackUrlW set the components related to net_loc to NULL when net_loc isn't present in the input URL. --- dlls/wininet/internet.c | 22 +++++++++++++--------- dlls/wininet/tests/http.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 73c3a15c498..42eb61de1a8 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -1337,13 +1337,13 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR break; } + lpUC->nScheme = INTERNET_SCHEME_UNKNOWN; + lpUC->nPort = INTERNET_INVALID_PORT_NUMBER; + /* Parse */ lpszParam = strpbrkW(lpszap, lpszSeparators); - if (lpszParam != NULL) - { - SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength, - lpszParam, dwUrlLength-(lpszParam-lpszUrl)); - } + SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength, + lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0); if (bIsAbsolute) /* Parse :[//] */ { @@ -1425,7 +1425,6 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR { SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost); - lpUC->nPort = 0; lpszcp=lpszNetLoc; } else @@ -1444,7 +1443,6 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR lpszcp=lpszHost; SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0); - lpUC->nPort = 0; } else { @@ -1467,7 +1465,7 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT; break; default: - lpUC->nPort = INTERNET_INVALID_PORT_NUMBER; + break; } } } @@ -1478,9 +1476,15 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0); SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0); SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0); - lpUC->nPort = 0; } } + else + { + SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0); + SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0); + SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0); + SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0); + } /* Here lpszcp points to: * diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 093fb7430bb..66115726d19 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -683,6 +683,7 @@ static void InternetCrackUrlW_test(void) 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R', '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A', 'U','L','T', 0 }; + static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 }; URL_COMPONENTSW comp; WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50]; BOOL r; @@ -762,6 +763,35 @@ static void InternetCrackUrlW_test(void) ok( comp.dwPasswordLength == 0, "password length wrong\n"); ok( comp.dwUrlPathLength == 15, "url length wrong\n"); ok( comp.dwExtraInfoLength == 29, "extra length wrong\n"); + + urlpart[0]=0; + scheme[0]=0; + extra[0]=0; + host[0]=0; + user[0]=0; + pwd[0]=0; + memset(&comp, 0, sizeof(comp)); + comp.dwStructSize = sizeof(comp); + comp.lpszScheme = scheme; + comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]); + comp.lpszHostName = host; + comp.dwHostNameLength = sizeof(host)/sizeof(host[0]); + comp.lpszUserName = user; + comp.dwUserNameLength = sizeof(user)/sizeof(user[0]); + comp.lpszPassword = pwd; + comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]); + comp.lpszUrlPath = urlpart; + comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]); + comp.lpszExtraInfo = extra; + comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]); + + r = InternetCrackUrlW(url2, 0, 0, &comp); + ok( r, "InternetCrackUrl failed, error %lx\n",GetLastError()); + ok(!comp.dwSchemeLength,".dwSchemeLength should be 0, but is %ld\n", comp.dwSchemeLength); + ok(!comp.dwHostNameLength,".dwHostNameLength should be 0, but is %ld\n", comp.dwHostNameLength); + ok(!comp.dwUserNameLength,".dwUserNameLength should be 0, but is %ld\n", comp.dwUserNameLength); + ok(!comp.dwPasswordLength,".dwPasswordLength should be 0, but is %ld\n", comp.dwPasswordLength); + ok(!comp.dwExtraInfoLength,".dwExtraInfoLength should be 0, but is %ld\n", comp.dwExtraInfoLength); } static void InternetTimeFromSystemTimeA_test(void)