From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sun, 12 Mar 2017 15:49:03 +0000 Subject: [PATCH 2/3] ui-{repolist,atom}: fix repository URL escaping In-Reply-To: References: Message-ID: <9cee1891ad6a0607c8a82043d9e2705e2fb77d09.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 --- 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("\n"); if (host) { - char *repourl = cgit_repourl(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("", !sorted && section ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); - html(""); - repourl = cgit_repourl(ctx.repo->url); - html_link_open(repourl, NULL, NULL); - free(repourl); + html(""); html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); - html_link_close(); - html(""); + html(""); 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