about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2007-11-03 11:15:56 +0100
committerLars Hjemli <hjemli@gmail.com>2007-11-03 11:15:56 +0100
commit68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5 (patch)
treed5f4a784477c714e81ca3a4d675ce640a5989b94
parentAdd search parameters to cgit_log_link (diff)
downloadcgit-pink-68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5.tar.gz
cgit-pink-68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5.zip
Fix search form action/hidden fields
The search form didn't properly honor the current path, so this commit
fixes cgit_fileurl() and add_hidden_formfields() to make the issue go
away.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r--ui-shared.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/ui-shared.c b/ui-shared.c
index a03661a..88dd6b8 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -60,19 +60,21 @@ char *cgit_repourl(const char *reponame)
 char *cgit_fileurl(const char *reponame, const char *pagename,
 		   const char *filename, const char *query)
 {
+	char *tmp;
+	char *delim;
+
 	if (cgit_virtual_root) {
-		if (query)
-			return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame,
-				   pagename, filename?filename:"", query);
-		else
-			return fmt("%s/%s/%s/", cgit_virtual_root, reponame,
-				   pagename);
+		tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame,
+			  pagename, (filename ? filename:""));
+		delim = "?";
 	} else {
-		if (query)
-			return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
-		else
-			return fmt("?r=%s&amp;p=%s", reponame, pagename);
+		tmp = fmt("?url=%s/%s/%s", reponame, pagename,
+			  (filename ? filename : ""));
+		delim = "&";
 	}
+	if (query)
+		tmp = fmt("%s%s%s", tmp, delim, query);
+	return tmp;
 }
 
 char *cgit_pageurl(const char *reponame, const char *pagename,
@@ -421,13 +423,15 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
 	return 0;
 }
 
-void add_hidden_formfields(int incl_head, int incl_search)
+void add_hidden_formfields(int incl_head, int incl_search, char *page)
 {
+	char *url;
+
 	if (!cgit_virtual_root) {
-		if (cgit_query_repo)
-			html_hidden("r", cgit_query_repo);
-		if (cgit_query_page)
-			html_hidden("p", cgit_query_page);
+		url = fmt("%s/%s", cgit_query_repo, page);
+		if (cgit_query_path)
+			url = fmt("%s/%s", url, cgit_query_path);
+		html_hidden("url", url);
 	}
 
 	if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch))
@@ -483,7 +487,7 @@ void cgit_print_pageheader(char *title, int show_search)
 
 		html("<p>\n<h1>branch</h1>\n");
 		html("<form method='get' action=''>\n");
-		add_hidden_formfields(0, 1);
+		add_hidden_formfields(0, 1, cgit_query_page);
 		html("<select name='h' onchange='this.form.submit();'>\n");
 		for_each_branch_ref(print_branch_option, cgit_query_head);
 		html("</select>\n");
@@ -491,9 +495,11 @@ void cgit_print_pageheader(char *title, int show_search)
 
 		html("<p>\n<h1>search</h1>\n");
 		html("<form method='get' action='");
-		html_attr(cgit_pageurl(cgit_query_repo, "log", NULL));
+		if (cgit_virtual_root)
+			html_attr(cgit_fileurl(cgit_query_repo, "log",
+					       cgit_query_path, NULL));
 		html("'>\n");
-		add_hidden_formfields(1, 0);
+		add_hidden_formfields(1, 0, "log");
 		html("<select name='qt'>\n");
 		html_option("grep", "log msg", cgit_query_grep);
 		html_option("author", "author", cgit_query_grep);
cgit-pink/commit/ui-log.c?h=1.3.0&id=71ba7187e5eeeaf2f66bc27bc3b48a2014d37bb7&follow=1'>ui-log: ban strcpy()Christian Hesse Git upstream bans strcpy() with commit: automatically ban strcpy() c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev