Am 13.11.26 um 14:00 schrieb Ruediger Pluem via dev:


On 11/13/26 12:24 PM, Rainer Jung wrote:
Hi there,

if a uri string does not contain an explicit port, apr_uri_parse does not add 
the default port from the scheme.

Although uri/apr_uri.c contains the line

893         uptr->port = apr_uri_port_of_scheme(uptr->scheme);

it doesn't reach it when the port is missing:

872         if (s == NULL) {
873             /* we expect the common case to have no port */
874             uptr->hostname = apr_pstrmemdup(p,
875                                             hostinfo + v6_offset1,
876                                             uri - hostinfo - v6_offset2);
877             goto deal_with_path;
878         }

So it jumps back to the deal_with_path label and the code there always returns 
without getting back to line 893.

Is it desirable for apr_uri_parse to add the default port for a scheme? If so, 
should it be a 1.7.x+ patch only or would that be a

I think this makes kind of sense. If I read the code correctly

http://somewhere:/

would give you port 80

Indeed, tested against APR 1.6.6.

http://somewhere/

would not set the port. This sounds wrong. For reconstructing a URL from an 
apr_uri_t apr_uri_unparse does not add a port
explicitly if the port is 0 or if the port is the same as the default port for 
this scheme. Hence at least for code
that reconstructs an URL through apr_uri_unparse setting the default port in 
apr_uri_parse would not change this.
Other reconstruction code might act differently.

There is another difference between the two case above that might be a bug or 
not:
The first case returns an empty string for port_str. In the second case 
port_str is NULL.
I am not sure if it makes sense to keep this behavior to indicate both 
different cases in the original URL.

No strong opinion concerning the desired semantics of port_str. For me it would be finde to keep it as-is.

Another topic is whether we should set port_str to the default port in case no 
port was specified. I think the current behavior of
not doing this is good as it reflects what was found in the URL string.


valid backport to 1.6.x as well?

I would tink so.


I can create a PR if this seems desirable.

You can, but APR is still on Subversion :-)
Oh well ...

Thanks,

Rainer

Reply via email to