Robert Shearman : wininet: Host name isn't present when two slashes aren' t present in InternetCrackUrl.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Mar 13 08:46:41 CST 2006


Module: wine
Branch: refs/heads/master
Commit: f18305b176b40bb9303aa2933855973b00e9270d
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=f18305b176b40bb9303aa2933855973b00e9270d

Author: Robert Shearman <rob at codeweavers.com>
Date:   Sat Mar 11 18:10:57 2006 +0000

wininet: Host name isn't present when two slashes aren't present in InternetCrackUrl.

The test for "about:" in InternetCrackUrlW should be more general so
that only URLs without double slashes should also be assumed not to
have a host name.

Add another test for this case and remove an unreliable
InternetCreateUrl test.

---

 dlls/wininet/internet.c   |   31 ++++++++++---------------------
 dlls/wininet/tests/http.c |   33 +++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index db6371b..5e303ae 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1345,7 +1345,6 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lp
     if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
     {
         LPCWSTR lpszNetLoc;
-        static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
 
         /* Get scheme first. */
         lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
@@ -1355,27 +1354,10 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lp
         /* Eat ':' in protocol. */
         lpszcp++;
 
-        /* if the scheme is "about", there is no host */
-        if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
+        /* double slash indicates the net_loc portion is present */
+        if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
         {
-            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
-        {
-            /* Skip over slashes. */
-            if (*lpszcp == '/')
-            {
-                lpszcp++;
-                if (*lpszcp == '/')
-                {
-                    lpszcp++;
-                    if (*lpszcp == '/')
-                        lpszcp++;
-                }
-            }
+            lpszcp += 2;
 
             lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
             if (lpszParam)
@@ -1488,6 +1470,13 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lp
                 }
             }
         }
+        else
+        {
+            SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
+            SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
+            SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
+            lpUC->nPort = 0;
+        }
     }
 
     /* Here lpszcp points to:
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index 4b6a2ad..9c7e213 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -31,6 +31,7 @@
 #include "wine/test.h"
 
 #define TEST_URL "http://www.winehq.org/site/about"
+#define TEST_URL_HOST "www.winehq.org"
 #define TEST_URL_PATH "/site/about"
 #define TEST_URL2 "http://www.myserver.com/myscript.php?arg=1"
 #define TEST_URL2_SERVER "www.myserver.com"
@@ -601,6 +602,23 @@ static void InternetCrackUrl_test(void)
   ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
   ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
 
+  zero_compsA(&urlComponents, 1, 1, 1, 1, 1, 1);
+  ok(InternetCrackUrlA(TEST_URL, strlen(TEST_URL), 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
+  ok(urlComponents.dwUrlPathLength == strlen(TEST_URL_PATH),".dwUrlPathLength should be %d, but is %ld\n", strlen(TEST_URL_PATH), urlComponents.dwUrlPathLength);
+  ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL_PATH,strlen(TEST_URL_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL_PATH, urlComponents.lpszUrlPath);
+  ok(urlComponents.dwHostNameLength == strlen(TEST_URL_HOST),".dwHostNameLength should be %d, but is %ld\n", strlen(TEST_URL_HOST), urlComponents.dwHostNameLength);
+  ok(!strncmp(urlComponents.lpszHostName,TEST_URL_HOST,strlen(TEST_URL_HOST)),"lpszHostName should be %s but is %s\n", TEST_URL_HOST, urlComponents.lpszHostName);
+  ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
+  ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
+  todo_wine {
+  ok(!urlComponents.lpszUserName, ".lpszUserName should have been set to NULL\n");
+  ok(!urlComponents.lpszPassword, ".lpszPassword should have been set to NULL\n");
+  ok(!urlComponents.lpszExtraInfo, ".lpszExtraInfo should have been set to NULL\n");
+  }
+  ok(!urlComponents.dwUserNameLength,".dwUserNameLength should be 0, but is %ld\n", urlComponents.dwUserNameLength);
+  ok(!urlComponents.dwPasswordLength,".dwPasswordLength should be 0, but is %ld\n", urlComponents.dwPasswordLength);
+  ok(!urlComponents.dwExtraInfoLength,".dwExtraInfoLength should be 0, but is %ld\n", urlComponents.dwExtraInfoLength);
+
   /*3. Check for %20 */
   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
   ok(InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
@@ -651,6 +669,13 @@ static void InternetCrackUrl_test(void)
   ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
      "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
     ret, GLE);
+
+  copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
+  ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
+  ok(ret, "InternetCrackUrl failed with %ld\n", GetLastError());
+  ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
+  ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
+  ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
 }
 
 static void InternetCrackUrlW_test(void)
@@ -860,14 +885,6 @@ static void InternetCreateUrlA_test(void
 		"Expected 0xdeadbeef, got %ld\n", GetLastError());
 	ok(len == -1, "Expected len -1, got %ld\n", len);
 
-	/* test garbage lpUrlComponets */
-	ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
-	SetLastError(0xdeadbeef);
-	ok(!ret, "Expected failure\n");
-	ok(GetLastError() == 0xdeadbeef,
-		"Expected 0xdeadbeef, got %ld\n", GetLastError());
-	ok(len == -1, "Expected len -1, got %ld\n", len);
-
 	/* test zero'ed lpUrlComponents */
 	ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
 	SetLastError(0xdeadbeef);




More information about the wine-cvs mailing list