From 68cf9b4f853177544a5d1c7b4a9eea4d2f5749d5 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 3 Nov 2007 11:15:56 +0100 Subject: 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 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&p=%s&%s", reponame, pagename, query); - else - return fmt("?r=%s&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("

\n

branch

\n"); html("
\n"); - add_hidden_formfields(0, 1); + add_hidden_formfields(0, 1, cgit_query_page); html("\n"); @@ -491,9 +495,11 @@ void cgit_print_pageheader(char *title, int show_search) html("

\n

search

\n"); html("\n"); - add_hidden_formfields(1, 0); + add_hidden_formfields(1, 0, "log"); html("