cgit

commit c6bea0375aa7898ea3229483741944303740801e

Author: Lars Hjemli <hjemli@gmail.com>

Merge branch 'lh/escape-urls'

* lh/escape-urls:
  ui-repolist + ui-shared: Use cgit_summary_link()
  ui-shared.c: add cgit_summary_link()
  ui-shared.c: use html_url_path() in repolink()
  html.c: add html_url_path

 html.c | 16 ++++++++++++++++
 html.h | 1 +
 ui-repolist.c | 8 ++------
 ui-shared.c | 20 ++++++++++++--------
 ui-shared.h | 1 +


diff --git a/html.c b/html.c
index 167127f31dd0d2f35c2dcd8e470df21f216f7e08..d7d9fd7007ff764c17ead46f23f00eaf44ade142 100644
--- a/html.c
+++ b/html.c
@@ -128,6 +128,22 @@ 	if (t!=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 038cf60ef098856c30ca4433e2e82970f34c73c2..a55d4b2d3563d56f6e7a56d5ae70b68cb1496727 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);




diff --git a/ui-repolist.c b/ui-repolist.c
index 725338b33e63e9254f1db5bddc66393fdf1e1b0b..ab050c788af1ca58564f9dd70c7ebc984feadabb 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -131,9 +131,7 @@ 			last_group = ctx.repo->group;
 		}
 		htmlf("<tr><td class='%s'>",
 		      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("</td><td>");
 		html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
 		html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
@@ -145,9 +143,7 @@ 		print_modtime(ctx.repo);
 		html("</td>");
 		if (ctx.cfg.enable_index_links) {
 			html("<td>");
-			html_link_open(cgit_repourl(ctx.repo->url),
-				       NULL, "button");
-			html("summary</a>");
+			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 a2f636c73d9dfb6da5b3e091ba8acdcbe2d5823a..1fc5c0978bde754ce540285cc9300ca84159d2bf 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -206,17 +206,17 @@ 		html("'");
 	}
 	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);
@@ -255,6 +255,11 @@ 	}
 	html("'>");
 	html_txt(name);
 	html("</a>");
+}
+
+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,
@@ -598,8 +603,7 @@ 	html("");
 	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("</td><td class='form'>");
 		html("<form method='get' action=''>\n");
 		add_hidden_formfields(0, 1, ctx->qry.page);
@@ -627,8 +631,8 @@ 	html("\n");
 
 	html("<table class='tabs'><tr><td>\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,




diff --git a/ui-shared.h b/ui-shared.h
index 747f09292fd4e571e1f1e8a0fa71e6c5b21ef2fd..0cd5ed1e25a7546475d92c02ee26e17343fcb045 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -10,6 +10,7 @@ 			  const char *query);
 
 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,