Diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/html.c | 17 | |
| -rw-r--r-- | source/html.h | 7 | |
| -rw-r--r-- | source/ui-shared.c | 4 |
3 files changed, 26 insertions, 2 deletions
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; diff --git a/source/html.h b/source/html.h index d3cd8fe..4c16f85 100644 --- a/source/html.h +++ b/source/html.h @@ -84,6 +84,13 @@ extern void html_url_path(const char *txt); */ extern void cgit_add_url_path(struct strbuf *sb, const char *txt); +/* + * Escape a whole url given in the configuration, such as a clone url, for an + * attribute value. Only a byte no url may carry is percent-encoded, so the + * scheme, the delimiters and any escape the url was written with are kept. + */ +extern void html_attr_url(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 985f33d..9e3757d 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -243,7 +243,7 @@ static void print_rel_vcs_link(const char *url) if (!has_uri_scheme(url)) return; html("<link rel='vcs-git' href='"); - html_attr(url); + html_attr_url(url); html("' title='"); html_attr(ctx.repo->name); html(" Git repository'>\n"); @@ -1736,7 +1736,7 @@ void cgit_print_clone_row(const char *url, int colspan) html("<a rel='vcs-git' title='"); html_attr(ctx.repo->name); html(" Git repository' href='"); - html_attr(href); + html_attr_url(href); html("'>"); html_txt(url); html("</a></td></tr>\n"); |
