Commit 004e1be6 authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

urlmon: Implemented canonicalization for URI fragments.

parent 27ec56ea
......@@ -65,6 +65,9 @@ typedef struct {
INT query_start;
DWORD query_len;
INT fragment_start;
DWORD fragment_len;
} Uri;
typedef struct {
......@@ -2749,6 +2752,56 @@ static BOOL canonicalize_query(const parse_data *data, Uri *uri, DWORD flags, BO
return TRUE;
}
static BOOL canonicalize_fragment(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
const WCHAR *ptr, *end;
const BOOL known_scheme = data->scheme_type != URL_SCHEME_UNKNOWN;
if(!data->fragment) {
uri->fragment_start = -1;
uri->fragment_len = 0;
return TRUE;
}
uri->fragment_start = uri->canon_len;
end = data->fragment + data->fragment_len;
for(ptr = data->fragment; ptr < end; ++ptr) {
if(*ptr == '%') {
if(known_scheme && !(flags & Uri_CREATE_NO_DECODE_EXTRA_INFO)) {
WCHAR val = decode_pct_val(ptr);
if(is_unreserved(val)) {
if(!computeOnly)
uri->canon_uri[uri->canon_len] = val;
++uri->canon_len;
ptr += 2;
continue;
}
}
} else if(known_scheme && !is_unreserved(*ptr) && !is_reserved(*ptr)) {
if(!(flags & Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS) &&
!(flags & Uri_CREATE_NO_DECODE_EXTRA_INFO)) {
if(!computeOnly)
pct_encode_val(*ptr, uri->canon_uri+uri->canon_len);
uri->canon_len += 3;
continue;
}
}
if(!computeOnly)
uri->canon_uri[uri->canon_len] = *ptr;
++uri->canon_len;
}
uri->fragment_len = uri->canon_len - uri->fragment_start;
if(!computeOnly)
TRACE("(%p %p %x %d): Canonicalized fragment %s len=%d\n", data, uri, flags,
computeOnly, debugstr_wn(uri->canon_uri+uri->fragment_start, uri->fragment_len),
uri->fragment_len);
return TRUE;
}
/* Canonicalizes the scheme information specified in the parse_data using the specified flags. */
static BOOL canonicalize_scheme(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
uri->scheme_start = -1;
......@@ -2816,6 +2869,11 @@ static int compute_canonicalized_length(const parse_data *data, DWORD flags) {
return -1;
}
if(!canonicalize_fragment(data, &uri, flags, TRUE)) {
ERR("(%p %x): Failed to compute fragment length.\n", data, flags);
return -1;
}
TRACE("(%p %x): Finished computing canonicalized URI length. length=%d\n", data, flags, uri.canon_len);
return uri.canon_len;
......@@ -2869,6 +2927,12 @@ static HRESULT canonicalize_uri(const parse_data *data, Uri *uri, DWORD flags) {
return E_INVALIDARG;
}
if(!canonicalize_fragment(data, uri, flags, FALSE)) {
ERR("(%p %p %x): Unable to canonicalize fragment of the URI.\n",
data, uri, flags);
return E_INVALIDARG;
}
/* There's a possibility we didn't use all the space we allocated
* earlier.
*/
......
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