[PATCH] shlwapi: UrlCanonicalize should strip all the characters <= 32 from the end of the string (with testcase)
Mikołaj Zalewski
mikolaj at zalewski.pl
Fri Jun 27 16:08:39 CDT 2008
---
dlls/shlwapi/tests/url.c | 16 ++++++++++++++++
dlls/shlwapi/url.c | 2 +-
dlls/wininet/tests/internet.c | 7 +++++++
3 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/dlls/shlwapi/tests/url.c b/dlls/shlwapi/tests/url.c
index 37c0111..1836a99 100644
--- a/dlls/shlwapi/tests/url.c
+++ b/dlls/shlwapi/tests/url.c
@@ -579,6 +579,7 @@ static void test_UrlCanonicalizeW(void)
DWORD dwSize;
DWORD urllen;
HRESULT hr;
+ int i;
if (!pUrlCanonicalizeW) {
@@ -628,6 +629,21 @@ static void test_UrlCanonicalizeW(void)
"got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
+ /* check that the characters 1..32 are choped from the end of the string */
+ for (i = 1; i < 65536; i++)
+ {
+ WCHAR szUrl[128];
+ BOOL choped;
+ int pos;
+
+ MultiByteToWideChar(CP_UTF8, 0, "http://www.winehq.org/X", -1, szUrl, 128);
+ pos = lstrlenW(szUrl) - 1;
+ szUrl[pos] = i;
+ urllen = INTERNET_MAX_URL_LENGTH;
+ pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
+ choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
+ ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
+ }
}
/* ########################### */
diff --git a/dlls/shlwapi/url.c b/dlls/shlwapi/url.c
index 16031e8..2efe386 100644
--- a/dlls/shlwapi/url.c
+++ b/dlls/shlwapi/url.c
@@ -502,7 +502,7 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
debugstr_w(pszUrl), debugstr_w(lpszUrlCpy));
}
nLen = lstrlenW(lpszUrlCpy);
- while ((nLen > 0) && ((lpszUrlCpy[nLen-1] == '\r')||(lpszUrlCpy[nLen-1] == '\n')))
+ while ((nLen > 0) && ((lpszUrlCpy[nLen-1] <= ' ')))
lpszUrlCpy[--nLen]=0;
if(dwFlags & (URL_UNESCAPE | URL_FILE_USE_PATHURL))
diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c
index 9f08b77..6ee452d 100644
--- a/dlls/wininet/tests/internet.c
+++ b/dlls/wininet/tests/internet.c
@@ -20,6 +20,7 @@
#include <stdarg.h>
#include <string.h>
+#include <windows.h>
#include "windef.h"
#include "winbase.h"
#include "wininet.h"
@@ -113,6 +114,12 @@ static void test_InternetCanonicalizeUrlA(void)
"got %u and %u with size %u for '%s' (%d)\n",
res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
+ /* test with trailing space */
+ dwSize = 256;
+ res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
+ ok(res == 1, "InternetCanonicalizeUrlA failed\n");
+ ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
+
res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
ok(!res, "InternetSetOptionA succeeded\n");
ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
--
1.5.4
--------------070604050508050009010806--
More information about the wine-patches
mailing list