git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] gitweb generates wrong links in grep search results (git_search_files)

From
Thomas Perl <th.perl@gmail.com>
Date
Jan 2, 2012, 13:29 UTC
Message-ID
<CA+uOhx6i-07kW8K0y3Co++2ABD=Lmaq3r4h1hN4YLskAE+hR1Q@mail.gmail.com>
Hi,

I think I found a bug in gitweb when grep'ing for text in a branch different from "master". Here's how to reproduce it:

1. Have a project with a master branch and a branch different from master
2. Start gitweb for that project (e.g. using "git instaweb") and open
it in a web browser
3. Switch to the non-master branch (e.g.
http://127.0.0.1:1234/?p=.git;a=shortlog;h=refs/heads/mynonmasterbranch)
4. In the top right search box, select "grep" in the combo box and
enter a text that only appears in the non-master branch
5. Submit the search by pressing enter, you should be at:
http://127.0.0.1:1234/?p=.git&a=search&h=refs%2Fheads%2Fmynonmasterbranch&st=grep&s=somesearchtext

ACTUAL RESULT In that list of results, you should now see some files matching the search - note that the links for the file names and the line numbers go to e.g. http://127.0.0.1:1234/?p=.git;a=blob;f=somefile.txt for a file "somefile.txt". The links therefore go to the master branch, while the search results refer to the non-master branch.

EXPECTED RESULT The link should (presumably) go to http://127.0.0.1:1234/?p=.git;a=blob;hb=refs%2Fheads%2Fmynonmasterbranch;f=somefile.txt so that when the link is clicked, the right file (somefile.txt in mynonmasterbranch) is shown.

I also investigated a bit in where the problem happens, and nailed it down to: gitweb/gitweb.perl, sub git_search_files, line 5871 in commit 17b4e93d5b849293e6a3659bbc4075ed8a6e97e2 (current master tip of https://github.com/gitster/git). I haven't looked at the intrinsics of the "href" sub, but I believe that it should somehow get the "h" parameter from the original page and incorporate it into the final link (as "hb" parameter?) to the file. The same fix that is applied there then also needs to be applied at line 5891 (same commit, same file).

No patch, because after several tries, I didn't get it to work, my Perl foo might not be up to the task, and I believe that someone more familiar with gitweb's code base might have an easier time to fix this.

Thanks, Thomas

Next: Junio C Hamano
Message 1 of 7 in “[BUG] gitweb generates wrong links in grep search results (git_search_files)”
  1. Thomas PerlJan 2, 2012
  2. Junio C HamanoJan 4, 2012
  3. Jakub NarębskiJan 4, 2012
  4. 1/2 gitweb: Fix file links in "grep" searchJakub Narebski, Jan 5, 2012
  5. 2/2 gitweb: Harden "grep" search against filenames with ':'Jakub Narebski, Jan 5, 2012
  6. Thomas PerlJan 13, 2012
  7. Junio C HamanoJan 13, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.