Re: [PATCH 2/3] credential: teach `credential_from_url()` a non-strict mode
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 22, 2020, 22:29 UTC
- Message-ID
- <xmqqh7xbi28f.fsf@gitster.c.googlers.com>
- In-Reply-To
- <1081841b16de31693473e72ff817bed5f0064dda.1587588665.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 19 quoted lines
> - if (!proto_end || proto_end == url) {
> + if (strict && (!proto_end || proto_end == url)) {
> if (!quiet)
> warning(_("url has no scheme: %s"), url);
> return -1;
> }
> - cp = proto_end + 3;
> + cp = proto_end ? proto_end + 3 : url;
> at = strchr(cp, '@');
> colon = strchr(cp, ':');
> slash = strchrnul(cp, '/');
> @@ -382,8 +382,10 @@ int credential_from_url_gently(struct credential *c, const char *url,
> host = at + 1;
> }
>
> - c->protocol = xmemdupz(url, proto_end - url);
> - c->host = url_decode_mem(host, slash - host);
> + if (proto_end && proto_end - url > 0)
> + c->protocol = xmemdupz(url, proto_end - url);Missing "proto://" under non-strict mode would leave c->protocol NULL (not "") here, as described in [0/3].
Here, slash would be pointing at one of "/?#" at the end of the host and url would be pointing at...? E.g. for "http:///path", URL points at 'h' at the beginning, proto_end points at ':', cp points at the last '/' before "path" and slash is the same as cp. host points at cp as there is no '@' at sign.
> + if (slash - url > 0) > + c->host = url_decode_mem(host, slash - host);
This wants to make c->host NULL when host is missing, as described in [0/3].
Shouldn't the condition based on "slash - host", though?
Other than that, it looks sensible.