Diff options
Diffstat (limited to 'source/ui-shared.c')
| -rw-r--r-- | source/ui-shared.c | 16 |
1 file changed, 13 insertions, 3 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index 788551d..985f33d 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1662,7 +1662,8 @@ int cgit_refuse_pathspec_magic(const char *path) return -1; } -static void add_clone_urls(void (*fn)(const char *), char *urls, char *suffix) +static void add_clone_urls(void (*fn)(const char *), const char *urls, + const char *suffix, int expand) { struct strbuf **url_list = strbuf_split_str(urls, ' ', 0); int i; @@ -1671,6 +1672,15 @@ static void add_clone_urls(void (*fn)(const char *), char *urls, char *suffix) strbuf_rtrim(url_list[i]); if (url_list[i]->len == 0) continue; + // Each template is expanded after the split, as a value such + // as $CGIT_REPO_URL may hold a space. The expansion is copied + // out of its static buffer, since fn may expand the list again. + if (expand) { + const char *url = cgit_expand_macros(url_list[i]->buf); + + strbuf_reset(url_list[i]); + strbuf_addstr(url_list[i], url); + } if (suffix && *suffix) strbuf_addf(url_list[i], "/%s", suffix); fn(url_list[i]->buf); @@ -1682,9 +1692,9 @@ static void add_clone_urls(void (*fn)(const char *), char *urls, char *suffix) void cgit_add_clone_urls(void (*fn)(const char *)) { if (ctx.repo->clone_url) - add_clone_urls(fn, cgit_expand_macros(ctx.repo->clone_url), NULL); + add_clone_urls(fn, ctx.repo->clone_url, NULL, 1); else if (ctx.cfg.clone_prefix) - add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); + add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url, 0); } static char *http_clone_url; |
