List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 2/3] ui-{repolist,atom}: fix repository URL escaping
Date: Sun, 12 Mar 2017 15:49:03 +0000	[thread overview]
Message-ID: <9cee1891ad6a0607c8a82043d9e2705e2fb77d09.1489333714.git.john@keeping.me.uk> (raw)
In-Reply-To: <db13fe9fe43ffd657fc4a0eef9c9d2ad6944b68f.1489333714.git.john@keeping.me.uk>

Remove cgit_repourl() and replace it with a new function that prints a
suitable escaped version of the repository URL designed for use in an
attribute value.  There are only two places that use this at the moment
and both want the value to be used in attribute context.

We could introduce new escaping functions to let us keep cgit_repourl()
and return a suitable escaped string, but there's no need for us to be
doing memory management here so this ends up simplifying the call sites.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 tests/t0101-index.sh |  2 +-
 ui-atom.c            |  4 +---
 ui-repolist.c        | 11 ++++-------
 ui-shared.c          | 13 ++++++++-----
 ui-shared.h          |  3 ++-
 5 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh
index 6450b9b..91c1355 100755
--- a/tests/t0101-index.sh
+++ b/tests/t0101-index.sh
@@ -11,7 +11,7 @@ test_expect_success 'find bar description' 'grep "the bar repo" tmp'
 test_expect_success 'find foo+bar repo' 'grep ">foo+bar<" tmp'
 test_expect_success 'verify foo+bar link' 'grep "/foo+bar/" tmp'
 test_expect_success 'verify "with%20space" link' 'grep "/with%20space/" tmp'
-test_expect_failure 'no links with space in path' '! grep "href=./with space/" tmp'
+test_expect_success 'no links with space in path' '! grep "href=./with space/" tmp'
 test_expect_success 'no tree-link' '! grep "foo/tree" tmp'
 test_expect_success 'no log-link' '! grep "foo/log" tmp'
 
diff --git a/ui-atom.c b/ui-atom.c
index 41838d3..671fc15 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -130,13 +130,11 @@ void cgit_print_atom(char *tip, char *path, int max_count)
 	html_txt(ctx.repo->desc);
 	html("</subtitle>\n");
 	if (host) {
-		char *repourl = cgit_repourl(ctx.repo->url);
 		html("<link rel='alternate' type='text/html' href='");
 		html(cgit_httpscheme());
 		html_attr(host);
-		html_attr(repourl);
+		cgit_repo_url_path(ctx.repo->url);
 		html("'/>\n");
-		free(repourl);
 	}
 	while ((commit = get_revision(&rev)) != NULL) {
 		add_entry(commit, host);
diff --git a/ui-repolist.c b/ui-repolist.c
index b57ea60..e1302b4 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -275,7 +275,6 @@ void cgit_print_repolist(void)
 	int i, columns = 3, hits = 0, header = 0;
 	char *last_section = NULL;
 	char *section;
-	char *repourl;
 	int sorted = 0;
 
 	if (!any_repos_visible()) {
@@ -330,13 +329,11 @@ void cgit_print_repolist(void)
 		htmlf("<tr><td class='%s'>",
 		      !sorted && section ? "sublevel-repo" : "toplevel-repo");
 		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
-		html("</td><td>");
-		repourl = cgit_repourl(ctx.repo->url);
-		html_link_open(repourl, NULL, NULL);
-		free(repourl);
+		html("</td><td><a href='");
+		cgit_repo_url_path(ctx.repo->url);
+		html("'>");
 		html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
-		html_link_close();
-		html("</td><td>");
+		html("</a></td><td>");
 		if (ctx.cfg.enable_index_owner) {
 			if (ctx.repo->owner_filter) {
 				cgit_open_filter(ctx.repo->owner_filter);
diff --git a/ui-shared.c b/ui-shared.c
index 2e4fcd9..4aca983 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -92,12 +92,15 @@ const char *cgit_loginurl(void)
 	return login_url;
 }
 
-char *cgit_repourl(const char *reponame)
+void cgit_repo_url_path(const char *reponame)
 {
-	if (ctx.cfg.virtual_root)
-		return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
-	else
-		return fmtalloc("?r=%s", reponame);
+	if (ctx.cfg.virtual_root) {
+		html_url_path(ctx.cfg.virtual_root);
+		html_url_path(reponame);
+	} else {
+		html("?r=");
+		html_url_arg(reponame);
+	}
 }
 
 char *cgit_fileurl(const char *reponame, const char *pagename,
diff --git a/ui-shared.h b/ui-shared.h
index 87799f1..90dfcbc 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -6,7 +6,6 @@ extern char *cgit_hosturl(void);
 extern const char *cgit_rooturl(void);
 extern char *cgit_currenturl(void);
 extern const char *cgit_loginurl(void);
-extern char *cgit_repourl(const char *reponame);
 extern char *cgit_fileurl(const char *reponame, const char *pagename,
 			  const char *filename, const char *query);
 extern char *cgit_pageurl(const char *reponame, const char *pagename,
@@ -14,6 +13,8 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
 
 extern void cgit_add_clone_urls(void (*fn)(const char *));
 
+extern void cgit_repo_url_path(const char *reponame);
+
 extern void cgit_index_link(const char *name, const char *title,
 			    const char *class, const char *pattern, const char *sort, int ofs, int always_root);
 extern void cgit_summary_link(const char *name, const char *title,
-- 
2.12.0.415.g6c14041932.dirty



  reply	other threads:[~2017-03-12 15:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 15:49 [PATCH 1/3] tests: document handling of repository names with spaces john
2017-03-12 15:49 ` john [this message]
2017-03-12 15:49 ` [PATCH 3/3] html: remove unused functions john

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cee1891ad6a0607c8a82043d9e2705e2fb77d09.1489333714.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).