On 11/16/26 4:10 PM, Yann Ylavic wrote:
> On Mon, Nov 16, 2026 at 3:19 PM Rainer Jung <[email protected]> wrote:
>>>
>>> Can't we delay apr_uri_port_of_scheme() until we know there is no ":port"
>>> still?
>>
>> Due to the use of goto, the code jumps a bit back and forth. So I found
>> it more robust to set immediately a default port when the scheme is
>> found and then overwrite it when a specific port is found than to find
>> all the exit points after (not necessarily below) the port detection and
>> then fall back to the default.
>
> Looks like the below does it (full patch not cumulative, claude confirms).
> My concern is that apr_uri_port_of_scheme() is quite slow, though the
> common case is probably the one added here..
>
> diff -ru a/uri/apr_uri.c b/uri/apr_uri.c
> --- a/uri/apr_uri.c 2026-11-16 16:02:56.759516227 +0100
> +++ b/uri/apr_uri.c 2026-11-16 16:02:56.784734796 +0100
> @@ -999,6 +999,7 @@
> if (have_zone_id) {
> percent_decode_scope_zone_id(uptr->hostname);
> }
> + uptr->port = apr_uri_port_of_scheme(uptr->scheme);
> goto deal_with_path;
> }
> uptr->hostname = apr_pstrmemdup(p,
Sounds sensible. Maybe AI can help us generate all the test cases such that
we can be sure it works and keeps working after changes.
Regards
Rüdiger