From: Toon Claes Date: Mon, 11 May 2026 13:10:55 GMT Subject: Re: [PATCH v2 6/8] promisor-remote: trust known remotes matching acceptFromServerUrl Message-ID: <87qzninlb4.fsf@toon--20250203-5JQV3.mail-host-address-is-not-set> In-Reply-To: <20260427124108.3524129-7-christian.couder@gmail.com> Christian Couder writes: > +static bool match_one_url(const struct url_info *pi, const struct url_info *ui) > +{ > + const char *pat = pi->url; > + const char *url = ui->url; > + char *p_str, *u_str; > + bool res; > + > + /* > + * Schemes must match exactly. They are case-folded by > + * url_normalize(), so strncmp() suffices. > + */ > + if (pi->scheme_len != ui->scheme_len || strncmp(pat, url, pi->scheme_len)) > + return false; > + > + /* > + * Ports must match exactly. url_normalize() strips default > + * ports (like 443 for https), so length and content > + * comparisons are sufficient. > + */ > + if (pi->port_len != ui->port_len || > + strncmp(pat + pi->port_off, url + ui->port_off, pi->port_len)) > + return false; > + > + /* > + * Match host and path separately to prevent a '*' in the host > + * portion of the pattern from matching across the '/' > + * boundary into the path. Use WM_PATHNAME for the host so '*' > + * cannot cross '/' there, and 0 for the path so '*' can still > + * match multi-level paths. > + */ > + > + p_str = xstrndup(pat + pi->host_off, pi->host_len); > + u_str = xstrndup(url + ui->host_off, ui->host_len); > + res = !wildmatch(p_str, u_str, WM_PATHNAME); > + free(p_str); > + free(u_str); > + > + if (!res) I feel it's a bit confusing your negating the result from wildmatch() to negate it here again? Maybe keep using the int return value, or rename the variable to 'matches' ? > + return false; > + > + p_str = xstrndup(pat + pi->path_off, pi->path_len); > + u_str = xstrndup(url + ui->path_off, ui->path_len); > + res = !wildmatch(p_str, u_str, 0); > + free(p_str); > + free(u_str); > + > + return res; > +} -- Cheers, Toon