From 5703446c1225212478731b884a215cac77155c59 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 19:29:15 -1000 Subject: Percent-encode a clone url in its href MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An href carried git://example.org/dépôt.git as it was, and the space of "with space" too, neither of which a url may hold. html_url_path would also encode the plus of git+ssh, which breaks the scheme, and the percent of an escape the url was written with, so a whole url gets a helper that encodes only the bytes RFC 3986 allows nowhere. --- source/html.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/html.c') diff --git a/source/html.c b/source/html.c index bc7a722..ce9344d 100644 --- a/source/html.c +++ b/source/html.c @@ -404,6 +404,23 @@ void cgit_add_url_path(struct strbuf *sb, const char *txt) } } +void html_attr_url(const char *txt) +{ + struct strbuf url = STRBUF_INIT; + + // These are the bytes RFC 3986 allows in no part of a url. + for (; *txt; txt++) { + unsigned char c = *txt; + + if (c <= ' ' || c >= 0x7f || strchr("\"<>\\^`{|}", c)) + strbuf_addstr(&url, url_escape_table[c]); + else + strbuf_addch(&url, c); + } + html_attr(url.buf); + strbuf_release(&url); +} + void html_url_arg(const char *txt) { const char *p = txt; -- cgit 2.12.1