Skip to content

Commit 3e6a0e6

Browse files
Patrick Steinhardtgitster
authored andcommitted
urlmatch: enable normalization of URLs with globs
The `url_normalize` function is used to validate and normalize URLs. As such, it does not allow for some special characters to be part of the URLs that are to be normalized. As we want to allow using globs in some configuration keys making use of URLs, namely `http.<url>.<key>`, but still normalize them, we need to somehow enable some additional allowed characters. To do this without having to change all callers of `url_normalize`, where most do not actually want globbing at all, we split off another function `url_normalize_1`. This function accepts an additional parameter `allow_globs`, which is subsequently called by `url_normalize` with `allow_globs=0`. As of now, this function is not used with globbing enabled. A caller will be added in the following commit. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3343995 commit 3e6a0e6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

urlmatch.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int append_normalized_escapes(struct strbuf *buf,
6363
return 1;
6464
}
6565

66-
char *url_normalize(const char *url, struct url_info *out_info)
66+
static char *url_normalize_1(const char *url, struct url_info *out_info, char allow_globs)
6767
{
6868
/*
6969
* Normalize NUL-terminated url using the following rules:
@@ -191,7 +191,12 @@ char *url_normalize(const char *url, struct url_info *out_info)
191191
strbuf_release(&norm);
192192
return NULL;
193193
}
194-
spanned = strspn(url, URL_HOST_CHARS);
194+
195+
if (allow_globs)
196+
spanned = strspn(url, URL_HOST_CHARS "*");
197+
else
198+
spanned = strspn(url, URL_HOST_CHARS);
199+
195200
if (spanned < colon_ptr - url) {
196201
/* Host name has invalid characters */
197202
if (out_info) {
@@ -380,6 +385,11 @@ char *url_normalize(const char *url, struct url_info *out_info)
380385
return result;
381386
}
382387

388+
char *url_normalize(const char *url, struct url_info *out_info)
389+
{
390+
return url_normalize_1(url, out_info, 0);
391+
}
392+
383393
static size_t url_match_prefix(const char *url,
384394
const char *url_prefix,
385395
size_t url_prefix_len)

0 commit comments

Comments
 (0)