diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Encode repository urls and the feed branch
Links built from the repository url, among them the description link
on the index and the Atom and refs links, wrote it as configured, so a
name holding a space, '#' or '?' broke them. The feed link in the page
head did the same with the branch, which turned a '+' into a space.
Diffstat (limited to 'source/ui-shared.c')
| -rw-r--r-- | source/ui-shared.c | 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 23 insertions, 23 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index f762fd7..409ad40 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -651,11 +651,8 @@ static void print_repo_tabs(void) static void print_repo_search(void) { html("<form class='search' role='search' method='get' action='"); - if (ctx.cfg.virtual_root) { - char *fileurl = cgit_fileurl(ctx.qry.repo, "log", ctx.qry.vpath, NULL); - html_url_path(fileurl); - free(fileurl); - } + if (ctx.cfg.virtual_root) + write_page_url("log", ctx.qry.vpath); html("'>\n"); cgit_add_hidden_formfields(1, 0, "log"); html("<select name='qt' aria-label='Search type'>\n"); @@ -896,10 +893,17 @@ const char *cgit_loginurl(void) char *cgit_repourl(const char *reponame) { - if (ctx.cfg.virtual_root) - return cgit_fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame); - else - return cgit_fmtalloc("?r=%s", reponame); + struct strbuf sb = STRBUF_INIT; + + if (ctx.cfg.virtual_root) { + strbuf_addstr(&sb, ctx.cfg.virtual_root); + cgit_add_url_path(&sb, reponame); + strbuf_addch(&sb, '/'); + } else { + strbuf_addstr(&sb, "?r="); + cgit_add_url_path(&sb, reponame); + } + return strbuf_detach(&sb, NULL); } char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, @@ -908,16 +912,17 @@ char *cgit_fileurl(const char *reponame, const char *pagename, const char *filen struct strbuf sb = STRBUF_INIT; const char *delim; - // The result is a raw URL, so the query joiner is a bare ampersand - // and each sink escapes the whole string for wherever it lands. + // The query joiner is a bare ampersand, because each sink escapes the + // whole string for wherever it lands. if (ctx.cfg.virtual_root) { - strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame, pagename, - filename ? filename : ""); + strbuf_addstr(&sb, ctx.cfg.virtual_root); delim = "?"; } else { - strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename, (filename ? filename : "")); + strbuf_addstr(&sb, "?url="); delim = "&"; } + cgit_add_url_path(&sb, reponame); + strbuf_addf(&sb, "/%s/%s", pagename, filename ? filename : ""); if (query) strbuf_addf(&sb, "%s%s", delim, query); return strbuf_detach(&sb, NULL); @@ -1509,7 +1514,7 @@ void cgit_redirect(const char *url, const char *query, bool permanent) { htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved Permanently" : "Found"); html("Location: "); - html_url_path(url); + html_header_query(url); if (query) html_header_query(query); html("\n\n"); @@ -1580,18 +1585,13 @@ void cgit_print_docstart(void) html("'>\n"); } if (host && ctx.repo && ctx.qry.head) { - char *fileurl; - struct strbuf sb = STRBUF_INIT; - strbuf_addf(&sb, "h=%s", ctx.qry.head); - html("<link rel='alternate' title='Atom feed' href='"); html(cgit_httpscheme()); html_attr(host); - fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath, sb.buf); - html_attr(fileurl); + html(write_page_url("atom", ctx.qry.vpath) ? "&" : "?"); + html("h="); + html_url_arg(ctx.qry.head); html("' type='application/atom+xml'>\n"); - strbuf_release(&sb); - free(fileurl); } if (ctx.repo) cgit_add_clone_urls(print_rel_vcs_link); |
