From 22a597e56dc7fdea78ccbcb7466b45dd62cf7b32 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 5 Oct 2008 16:52:57 +0200 Subject: html.c: add html_url_path This function can be used to generate properly escaped path-components for links. Signed-off-by: Lars Hjemli --- html.c | 16 ++++++++++++++++ html.h | 1 + 2 files changed, 17 insertions(+) diff --git a/html.c b/html.c index 167127f..d7d9fd7 100644 --- a/html.c +++ b/html.c @@ -128,6 +128,22 @@ void html_attr(char *txt) html(txt); } +void html_url_path(char *txt) +{ + char *t = txt; + while(t && *t){ + int c = *t; + if (c=='"' || c=='#' || c=='\'' || c=='?') { + write(htmlfd, txt, t - txt); + write(htmlfd, fmt("%%%2x", c), 3); + txt = t+1; + } + t++; + } + if (t!=txt) + html(txt); +} + void html_url_arg(char *txt) { char *t = txt; diff --git a/html.h b/html.h index 038cf60..a55d4b2 100644 --- a/html.h +++ b/html.h @@ -10,6 +10,7 @@ extern void html_status(int code, const char *msg, int more_headers); extern void html_txt(char *txt); extern void html_ntxt(int len, char *txt); extern void html_attr(char *txt); +extern void html_url_path(char *txt); extern void html_url_arg(char *txt); extern void html_hidden(char *name, char *value); extern void html_option(char *value, char *text, char *selected_value); -- cgit v1.2.3 From 44b208aa44c4cdf7e1e339bbd5b028c23da55a46 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 5 Oct 2008 16:54:44 +0200 Subject: ui-shared.c: use html_url_path() in repolink() This makes sure that reponames and paths are properly escaped when used as urls. Signed-off-by: Lars Hjemli --- ui-shared.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index a2f636c..2eddd2d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -206,17 +206,17 @@ static char *repolink(char *title, char *class, char *page, char *head, } html(" href='"); if (ctx.cfg.virtual_root) { - html_attr(ctx.cfg.virtual_root); + html_url_path(ctx.cfg.virtual_root); if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') html("/"); - html_attr(ctx.repo->url); + html_url_path(ctx.repo->url); if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') html("/"); if (page) { - html(page); + html_url_path(page); html("/"); if (path) - html_attr(path); + html_url_path(path); } } else { html(ctx.cfg.script_name); -- cgit v1.2.3 From e9d3bd544fe94ba5ade9ccf185328fcc2414814b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 5 Oct 2008 16:55:50 +0200 Subject: ui-shared.c: add cgit_summary_link() This function can be used to generate a link to the summary page for the currently active repo. Signed-off-by: Lars Hjemli --- ui-shared.c | 5 +++++ ui-shared.h | 1 + 2 files changed, 6 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 2eddd2d..ee3f6fe 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -257,6 +257,11 @@ static void reporevlink(char *page, char *name, char *title, char *class, html(""); } +void cgit_summary_link(char *name, char *title, char *class, char *head) +{ + reporevlink(NULL, name, title, class, head, NULL, NULL); +} + void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path) { diff --git a/ui-shared.h b/ui-shared.h index 747f092..0cd5ed1 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -10,6 +10,7 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename, extern void cgit_index_link(char *name, char *title, char *class, char *pattern, int ofs); +extern void cgit_summary_link(char *name, char *title, char *class, char *head); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_plain_link(char *name, char *title, char *class, char *head, -- cgit v1.2.3 From 49ecbbddf0659c6409befcfe8989f92196133cda Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 5 Oct 2008 17:16:36 +0200 Subject: ui-repolist + ui-shared: Use cgit_summary_link() This makes is possible to use cgit with repository urls containing special url characters like '#' and '?'. Signed-off-by: Lars Hjemli --- ui-repolist.c | 8 ++------ ui-shared.c | 7 +++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index 725338b..ab050c7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -131,9 +131,7 @@ void cgit_print_repolist() } htmlf("", ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); - html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); - html_txt(ctx.repo->name); - html_link_close(); + cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); html(""); html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); @@ -145,9 +143,7 @@ void cgit_print_repolist() html(""); if (ctx.cfg.enable_index_links) { html(""); - html_link_open(cgit_repourl(ctx.repo->url), - NULL, "button"); - html("summary"); + cgit_summary_link("summary", NULL, "button", NULL); cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0, NULL, NULL); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); diff --git a/ui-shared.c b/ui-shared.c index ee3f6fe..1fc5c09 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -603,8 +603,7 @@ void cgit_print_pageheader(struct cgit_context *ctx) if (ctx->repo) { cgit_index_link("index", NULL, NULL, NULL, 0); html(" : "); - reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"), - ctx->qry.head, NULL, NULL); + cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); html(""); html("
\n"); add_hidden_formfields(0, 1, ctx->qry.page); @@ -632,8 +631,8 @@ void cgit_print_pageheader(struct cgit_context *ctx) html("
\n"); if (ctx->repo) { - reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), - ctx->qry.head, NULL, NULL); + cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, + ctx->qry.head); cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, ctx->qry.sha1, NULL); cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, -- cgit v1.2.3