Commit 11a0c8cd authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

shlwapi: UrlCanonicalize: fix URL_DONT_SIMPLIFY.

- URL_DONT_SIMPLIFY should change '/' <-> '\' - Better '/' / '\' handling
parent 50c64c04
......@@ -72,7 +72,9 @@ const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
{"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"},
{"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"},
{"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"},
{"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar"}
{"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar"},
{"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar"},
{"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar"},
};
typedef struct _TEST_URL_ESCAPE {
......@@ -174,8 +176,10 @@ typedef struct _TEST_URL_COMBINE {
const TEST_URL_COMBINE TEST_COMBINE[] = {
{"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
{"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
/*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
{"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
{"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
{"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
{"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
{"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
......@@ -184,6 +188,7 @@ const TEST_URL_COMBINE TEST_COMBINE[] = {
{"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
{"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
{"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
{"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"}
};
struct {
......
......@@ -341,10 +341,6 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
nByteLen = (lstrlenW(pszUrl) + 1) * sizeof(WCHAR); /* length in bytes */
lpszUrlCpy = HeapAlloc(GetProcessHeap(), 0, nByteLen);
if (dwFlags & URL_DONT_SIMPLIFY)
memcpy(lpszUrlCpy, pszUrl, nByteLen);
else {
/*
* state =
* 0 initial 1,3
......@@ -377,7 +373,7 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
*wk2++ = *wk1++;
if (*wk1 != L'/') {state = 6; break;}
*wk2++ = *wk1++;
if((dwFlags & URL_FILE_USE_PATHURL) && *wk1 == '/')
if(*wk1 == '/' && (dwFlags & URL_FILE_USE_PATHURL))
wk1++;
state = 4;
break;
......@@ -403,22 +399,26 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
break;
case 5:
if (*wk1 != '/' && *wk1 != '\\') {state = 3; break;}
while(*wk1 == '/') {
while(*wk1 == '/' || *wk1 == '\\') {
*wk2++ = slash;
wk1++;
}
state = 6;
break;
case 6:
if(dwFlags & URL_DONT_SIMPLIFY) {
state = 3;
break;
}
/* Now at root location, cannot back up any more. */
/* "root" will point at the '/' */
root = wk2-1;
while (*wk1) {
TRACE("wk1=%c\n", (CHAR)*wk1);
mp = strchrW(wk1, '/');
mp2 = strchrW(wk1, '\\');
if(mp2 && mp2 < mp)
if(mp2 && (!mp || mp2 < mp))
mp = mp2;
if (!mp) {
nWkLen = strlenW(wk1);
......@@ -474,7 +474,6 @@ HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
HeapFree(GetProcessHeap(), 0, lpszUrlCpy);
return E_INVALIDARG;
}
}
*wk2 = L'\0';
TRACE("Simplified, orig <%s>, simple <%s>\n",
debugstr_w(pszUrl), debugstr_w(lpszUrlCpy));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment