urlmatch: add url_normalize_pattern() helper
In a following commit, we will need to normalize a URL glob pattern (which may contain '*' in the host portion) and extract its component offsets (host, path, etc.) for separate matching. Let's export a dedicated helper function url_normalize_pattern() for that purpose. It works like url_normalize(), but passes allow_globs=true to the internal url_normalize_1(), so that '*' characters in the host are accepted rather than rejected. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 27, 2026 at 16:08 UTC
58880c82feb460015153575dc02b9959e4d8a8a0
2 files changed
+17
urlmatch.c
+5
@@ -441,6 +441,11 @@ char *url_normalize(const char *url, struct url_info *out_info)
441
return url_normalize_1(url, out_info, false);
442
}
443
444
+char *url_normalize_pattern(const char *url, struct url_info *out_info)
445
+{
446
+ return url_normalize_1(url, out_info, true);
447
+}
448
+
449
char *url_parse(const char *url_orig, struct url_info *out_info)
450
{
451
struct strbuf url;
urlmatch.h
+12
@@ -37,6 +37,18 @@ struct url_info {
37
char *url_normalize(const char *, struct url_info *);
38
char *url_parse(const char *, struct url_info *);
39
40
+/*
41
+ * Like url_normalize(), but also allows '*' glob characters in the host
42
+ * portion. Use this when normalizing URL patterns from user configuration.
43
+ *
44
+ * Note that '*' is a valid path character per RFC 3986 (as a sub-delim),
45
+ * so glob patterns using '*' in the path are also accepted.
46
+ *
47
+ * Returns a newly allocated normalized string and fills out_info if
48
+ * non-NULL, or NULL if the pattern is invalid.
49
+ */
50
+char *url_normalize_pattern(const char *url, struct url_info *out_info);
51
+
52
struct urlmatch_item {
53
size_t hostmatch_len;
54
size_t pathmatch_len;