Commit b3ad7469 authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

urlmon: Added support for pre-processing URI strings.

parent 3c59b9c6
......@@ -3430,6 +3430,123 @@ static const uri_properties uri_tests[] = {
{URL_SCHEME_HTTP,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE},
}
},
/* Leading/Trailing whitespace is removed. */
{ " http://google.com/ ", 0, S_OK, FALSE,
Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|
Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
FALSE,
{
{"http://google.com/",S_OK,FALSE},
{"google.com",S_OK,FALSE},
{"http://google.com/",S_OK,FALSE},
{"google.com",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE},
{"google.com",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"/",S_OK,FALSE},
{"/",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"http://google.com/",S_OK,FALSE},
{"http",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE}
},
{
{Uri_HOST_DNS,S_OK,FALSE},
{80,S_OK,FALSE},
{URL_SCHEME_HTTP,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE}
}
},
{ "\t\t\r\nhttp\n://g\noogle.co\rm/\n\n\n", 0, S_OK, FALSE,
Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|
Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
FALSE,
{
{"http://google.com/",S_OK,FALSE},
{"google.com",S_OK,FALSE},
{"http://google.com/",S_OK,FALSE},
{"google.com",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE},
{"google.com",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"/",S_OK,FALSE},
{"/",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"http://google.com/",S_OK,FALSE},
{"http",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE}
},
{
{Uri_HOST_DNS,S_OK,FALSE},
{80,S_OK,FALSE},
{URL_SCHEME_HTTP,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE}
}
},
{ "http://g\noogle.co\rm/\n\n\n", Uri_CREATE_NO_PRE_PROCESS_HTML_URI, S_OK, FALSE,
Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|
Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
FALSE,
{
{"http://g%0aoogle.co%0dm/%0A%0A%0A",S_OK,FALSE},
{"g%0aoogle.co%0dm",S_OK,FALSE},
{"http://g%0aoogle.co%0dm/%0A%0A%0A",S_OK,FALSE},
{"g%0aoogle.co%0dm",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE},
{"g%0aoogle.co%0dm",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"/%0A%0A%0A",S_OK,FALSE},
{"/%0A%0A%0A",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"http://g\noogle.co\rm/\n\n\n",S_OK,FALSE},
{"http",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE}
},
{
{Uri_HOST_DNS,S_OK,FALSE},
{80,S_OK,FALSE},
{URL_SCHEME_HTTP,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE}
}
},
{ "zip://g\noogle.co\rm/\n\n\n", Uri_CREATE_NO_PRE_PROCESS_HTML_URI, S_OK, FALSE,
Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|
Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_SCHEME,
FALSE,
{
{"zip://g\noogle.co\rm/\n\n\n",S_OK,FALSE},
{"g\noogle.co\rm",S_OK,FALSE},
{"zip://g\noogle.co\rm/\n\n\n",S_OK,FALSE},
{"g\noogle.co\rm",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE},
{"g\noogle.co\rm",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"/\n\n\n",S_OK,FALSE},
{"/\n\n\n",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"zip://g\noogle.co\rm/\n\n\n",S_OK,FALSE},
{"zip",S_OK,FALSE},
{"",S_FALSE,FALSE},
{"",S_FALSE,FALSE}
},
{
{Uri_HOST_DNS,S_OK,FALSE},
{0,S_FALSE,FALSE},
{URL_SCHEME_UNKNOWN,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE}
}
}
};
......@@ -3486,7 +3603,9 @@ static const invalid_uri invalid_uri_tests[] = {
/* Known scheme types can't have invalid % encoded data in query string. */
{"http://google.com/?query=te%xx",0,FALSE},
/* Invalid % encoded data in fragment of know scheme type. */
{"ftp://google.com/#Test%xx",0,FALSE}
{"ftp://google.com/#Test%xx",0,FALSE},
{" http://google.com/",Uri_CREATE_NO_PRE_PROCESS_HTML_URI,FALSE},
{"\n\nhttp://google.com/",Uri_CREATE_NO_PRE_PROCESS_HTML_URI,FALSE}
};
typedef struct _uri_equality {
......
......@@ -626,6 +626,45 @@ static void compute_elision_location(const ipv6_address *address, const USHORT v
*count = max_len;
}
/* Removes all the leading and trailing white spaces or
* control characters from the URI and removes all control
* characters inside of the URI string.
*/
static BSTR pre_process_uri(LPCWSTR uri) {
BSTR ret;
DWORD len;
const WCHAR *start, *end;
WCHAR *buf, *ptr;
len = lstrlenW(uri);
start = uri;
/* Skip leading controls and whitespace. */
while(iscntrlW(*start) || isspaceW(*start)) ++start;
end = uri+len-1;
if(start == end)
/* URI consisted only of control/whitespace. */
ret = SysAllocStringLen(NULL, 0);
else {
while(iscntrlW(*end) || isspaceW(*end)) --end;
buf = heap_alloc(((end+1)-start)*sizeof(WCHAR));
if(!buf)
return NULL;
for(ptr = buf; start < end+1; ++start) {
if(!iscntrlW(*start))
*ptr++ = *start;
}
ret = SysAllocStringLen(buf, ptr-buf);
heap_free(buf);
}
return ret;
}
/* Converts the specified IPv4 address into an uint value.
*
* This function assumes that the IPv4 address has already been validated.
......@@ -3729,8 +3768,12 @@ HRESULT WINAPI CreateUri(LPCWSTR pwzURI, DWORD dwFlags, DWORD_PTR dwReserved, IU
ret->lpIUriVtbl = &UriVtbl;
ret->ref = 1;
/* Create a copy of pwzURI and store it as the raw_uri. */
ret->raw_uri = SysAllocString(pwzURI);
/* Pre process the URI, unless told otherwise. */
if(!(dwFlags & Uri_CREATE_NO_PRE_PROCESS_HTML_URI))
ret->raw_uri = pre_process_uri(pwzURI);
else
ret->raw_uri = SysAllocString(pwzURI);
if(!ret->raw_uri) {
heap_free(ret);
return E_OUTOFMEMORY;
......
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