diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 4a2f00132eb..5beb6223efe 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -3700,9 +3700,23 @@ static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort) (nPort == INTERNET_DEFAULT_GOPHER_PORT)) return TRUE; + if (nPort == INTERNET_INVALID_PORT_NUMBER) + return TRUE; + return FALSE; } +/* opaque urls do not fit into the standard url hierarchy and don't have + * two following slashes */ +static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme) +{ + return (nScheme != INTERNET_SCHEME_FTP) && + (nScheme != INTERNET_SCHEME_GOPHER) && + (nScheme != INTERNET_SCHEME_HTTP) && + (nScheme != INTERNET_SCHEME_HTTPS) && + (nScheme != INTERNET_SCHEME_FILE); +} + static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme) { int index; @@ -3742,7 +3756,9 @@ static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents, *lpdwUrlLength += strlenW(scheme); } - *lpdwUrlLength += strlen("://"); + (*lpdwUrlLength)++; /* ':' */ + if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName) + *lpdwUrlLength += strlen("//"); if (lpUrlComponents->lpszUserName) { @@ -3909,7 +3925,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, DWORD dwLen; INTERNET_SCHEME nScheme; - static const WCHAR colonSlashW[] = {':','/','/'}; + static const WCHAR slashSlashW[] = {'/','/'}; static const WCHAR percentD[] = {'%','d',0}; TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength); @@ -3960,8 +3976,15 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, lpszUrl += dwLen; } - memcpy(lpszUrl, colonSlashW, sizeof(colonSlashW)); - lpszUrl += sizeof(colonSlashW)/sizeof(colonSlashW[0]); + /* all schemes are followed by at least a colon */ + *lpszUrl = ':'; + lpszUrl++; + + if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName) + { + memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW)); + lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]); + } if (lpUrlComponents->lpszUserName) { diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 72ab72c5f0f..90a972c2d94 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -1111,11 +1111,9 @@ static void InternetCreateUrlA_test(void) len = strlen(CREATE_URL9); szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len); ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len); - todo_wine { ok(ret, "Expected success\n"); ok(len == strlen(CREATE_URL9), "Expected len %d, got %ld\n", strlen(CREATE_URL9), len); ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl); - } HeapFree(GetProcessHeap(), 0, szUrl); }