Skip to content
Snippets Groups Projects
Commit 2f099e1b authored by Tobias S. Josefowitz's avatar Tobias S. Josefowitz
Browse files

Standards.URI: Never use the input string as string representation

Case in scheme, host and so on also can desync the raw input uri from
the parsed components.
parent fc505d9b
No related branches found
No related tags found
No related merge requests found
...@@ -49,20 +49,12 @@ string raw_uri; ...@@ -49,20 +49,12 @@ string raw_uri;
// FIXME: What about decoding of Percent-Encoding (RFC3986 2.1)? // FIXME: What about decoding of Percent-Encoding (RFC3986 2.1)?
// cf pct-encoded in the functions below. // cf pct-encoded in the functions below.
protected enum cache_advice {
DO_NOT_CACHE,
MAY_CACHE,
};
// Parse authority component (according to RFC 1738, § 3.1) // Parse authority component (according to RFC 1738, § 3.1)
// Updated to RFC 3986 $ 3.2. // Updated to RFC 3986 $ 3.2.
// NOTE: Censors the userinfo from the @[authority] variable. // NOTE: Censors the userinfo from the @[authority] variable.
protected cache_advice parse_authority() protected void parse_authority()
{ {
string host_port = authority; string host_port = authority;
int default_port;
cache_advice advice = MAY_CACHE;
// authority = [ userinfo "@" ] host [ ":" port ] // authority = [ userinfo "@" ] host [ ":" port ]
if(sscanf(authority, "%[^@]@%s", string userinfo, host_port) == 2) if(sscanf(authority, "%[^@]@%s", string userinfo, host_port) == 2)
{ {
...@@ -71,28 +63,18 @@ protected cache_advice parse_authority() ...@@ -71,28 +63,18 @@ protected cache_advice parse_authority()
DEBUG("parse_authority(): user=%O, password=%O", user, password); DEBUG("parse_authority(): user=%O, password=%O", user, password);
} }
if(scheme) if(scheme)
default_port = port = Protocols.Ports.tcp[scheme]; // Set a good default á la RFC 1700 port = Protocols.Ports.tcp[scheme]; // Set a good default á la RFC 1700
// host = IP-literal / IPv4address / reg-name // host = IP-literal / IPv4address / reg-name
if (has_prefix(host_port, "[")) { if (has_prefix(host_port, "[")) {
// IP-literal = "[" ( IPv6address / IPvFuture ) "]" // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
// IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
if (sscanf(host_port, "[%s]%*[:]%d", host, port) == 3 sscanf(host_port, "[%s]%*[:]%d", host, port);
&& port == default_port)
{
advice = DO_NOT_CACHE;
}
} else { } else {
// IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet // IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
// reg-name = *( unreserved / pct-encoded / sub-delims ) // reg-name = *( unreserved / pct-encoded / sub-delims )
if (sscanf(host_port, "%[^:]%*[:]%d", host, port) == 3 sscanf(host_port, "%[^:]%*[:]%d", host, port);
&& port == default_port)
{
advice = DO_NOT_CACHE;
}
} }
DEBUG("parse_authority(): host=%O, port=%O", host, port); DEBUG("parse_authority(): host=%O, port=%O", host, port);
return advice;
} }
// Inherit all properties except raw_uri and base_uri from the URI uri. :-) // Inherit all properties except raw_uri and base_uri from the URI uri. :-)
...@@ -325,15 +307,11 @@ void reparse_uri(this_program|string|void base_uri) ...@@ -325,15 +307,11 @@ void reparse_uri(this_program|string|void base_uri)
// scheme is inherited from the base URI's scheme component. // scheme is inherited from the base URI's scheme component.
if(scheme) if(scheme)
{ {
int do_cache = 1;
if(authority) if(authority)
do_cache = parse_authority() == MAY_CACHE; parse_authority();
DEBUG("Scheme found! RFC 2396, §5.2, step 3 " DEBUG("Scheme found! RFC 2396, §5.2, step 3 "
"says we're absolute. Done!"); "says we're absolute. Done!");
if (do_cache)
sprintf_cache['s'] = raw_uri;
return; return;
} }
scheme = this_program::base_uri->scheme; scheme = this_program::base_uri->scheme;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment