From: Patrick Steinhardt Date: Thu, 26 Mar 2026 12:20:52 GMT Subject: Re: [PATCH 03/16] urlmatch: add url_is_valid_pattern() helper Message-ID: In-Reply-To: <20260323080520.887550-4-christian.couder@gmail.com> On Mon, Mar 23, 2026 at 09:05:06AM +0100, Christian Couder wrote: > diff --git a/urlmatch.c b/urlmatch.c > index 989bc7eb8b..a8cb6c3bee 100644 > --- a/urlmatch.c > +++ b/urlmatch.c > @@ -440,6 +440,18 @@ char *url_normalize(const char *url, struct url_info *out_info) > return url_normalize_1(url, out_info, false); > } > > +bool url_is_valid_pattern(const char *url) > +{ > + char *normalized = url_normalize_1(url, NULL, true); > + > + if (normalized) { > + free(normalized); > + return true; > + } > + > + return false; > +} We could simplify this implementation to: bool url_is_valid_pattern(const char *url) { char *normalized = url_normalize_1(url, NULL, true); free(normalized); return !!normalized; } > diff --git a/urlmatch.h b/urlmatch.h > index 5ba85cea13..4e01422a02 100644 > --- a/urlmatch.h > +++ b/urlmatch.h > @@ -36,6 +36,17 @@ struct url_info { > > char *url_normalize(const char *, struct url_info *); > > +/* > + * Return 'true' if the string looks like a valid URL or a valid URL pattern > + * (allowing '*' globs), 'false' otherwise. > + * > + * This is NOT a URL validation function. Full URL validation is NOT > + * performed. Some invalid host names are passed through this function > + * undetected. However, most all other problems that make a URL invalid > + * will be detected (including a missing host for non file: URLs). > + */ > +bool url_is_valid_pattern(const char *url); Okay, this comment is basically copied from `url_normalize_1()`, which makes sense. Patrick