Subject: [PATCH 03/16] urlmatch: add url_is_valid_pattern() helper

From: Christian Couder <[email-masked]>
Date: Mon, 23 Mar 2026 09:05:06 +0100

In a following commit, we will need to check if a URL that might have
glob patterns looks valid, so let's export a dedicated helper function
for that purpose.

Signed-off-by: Christian Couder <[email-masked]>
---
 urlmatch.c | 12 ++++++++++++
 urlmatch.h | 11 +++++++++++
 2 files changed, 23 insertions(+)

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;
+}
+
 static size_t url_match_prefix(const char *url,
 			       const char *url_prefix,
 			       size_t url_prefix_len)
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);
+
 struct urlmatch_item {
 	size_t hostmatch_len;
 	size_t pathmatch_len;
-- 
2.53.0.625.g20f70b52bb