From e112b278469c1104eef3059f188ee3bd433582c8 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 12:53:14 -1000 Subject: 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. --- source/html.c | 12 ++++++++++++ source/html.h | 8 ++++++++ source/ui-shared.c | 46 +++++++++++++++++++++++----------------------- source/ui-shared.h | 12 ++++++++++-- tests/t0101-index.sh | 10 ++++++++-- tests/t0303-robustness.sh | 6 ++++++ 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/source/html.c b/source/html.c index 367cea7..1a6b7c5 100644 --- a/source/html.c +++ b/source/html.c @@ -314,6 +314,18 @@ void html_url_path(const char *txt) html(txt); } +void cgit_add_url_path(struct strbuf *sb, const char *txt) +{ + for (; *txt; txt++) { + const char *esc = url_escape_table[(unsigned char)*txt]; + + if (esc) + strbuf_addstr(sb, esc); + else + strbuf_addch(sb, *txt); + } +} + void html_url_arg(const char *txt) { const char *p = txt; diff --git a/source/html.h b/source/html.h index 1960b6a..095804c 100644 --- a/source/html.h +++ b/source/html.h @@ -62,6 +62,14 @@ extern ssize_t html_ntxt(const char *txt, size_t len); extern void html_attr(const char *txt); extern void html_url_path(const char *txt); + +/* + * Append txt to sb with the escaping html_url_path writes, for a url that is + * assembled before it reaches a sink. Nothing is captured, so it is safe to + * call while a capture is open. + */ +extern void cgit_add_url_path(struct strbuf *sb, const char *txt); + extern void html_url_arg(const char *txt); extern void html_header_arg_in_quotes(const char *txt); extern void html_header_query(const char *txt); 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("