]> git.ipfire.org Git - thirdparty/git.git/commitdiff
urlmatch: enable normalization of URLs with globs
authorPatrick Steinhardt <patrick.steinhardt@elego.de>
Tue, 31 Jan 2017 09:01:44 +0000 (10:01 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 18:06:54 +0000 (10:06 -0800)
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 <patrick.steinhardt@elego.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
urlmatch.c

index 132d342bc12bf790f9964f179385aa4f08e6ae00..d350478c090b0c2ac264fe1483f2103ff8ac5ef7 100644 (file)
@@ -63,7 +63,7 @@ static int append_normalized_escapes(struct strbuf *buf,
        return 1;
 }
 
-char *url_normalize(const char *url, struct url_info *out_info)
+static char *url_normalize_1(const char *url, struct url_info *out_info, char allow_globs)
 {
        /*
         * Normalize NUL-terminated url using the following rules:
@@ -191,7 +191,12 @@ char *url_normalize(const char *url, struct url_info *out_info)
                strbuf_release(&norm);
                return NULL;
        }
-       spanned = strspn(url, URL_HOST_CHARS);
+
+       if (allow_globs)
+               spanned = strspn(url, URL_HOST_CHARS "*");
+       else
+               spanned = strspn(url, URL_HOST_CHARS);
+
        if (spanned < colon_ptr - url) {
                /* Host name has invalid characters */
                if (out_info) {
@@ -380,6 +385,11 @@ char *url_normalize(const char *url, struct url_info *out_info)
        return result;
 }
 
+char *url_normalize(const char *url, struct url_info *out_info)
+{
+       return url_normalize_1(url, out_info, 0);
+}
+
 static size_t url_match_prefix(const char *url,
                               const char *url_prefix,
                               size_t url_prefix_len)