{"thread":{"id":"15962","subject":"[PATCH/RFR&A] gitweb: Better processing format string in custom links in navbar","startedAt":"2008-10-19T07:07:12Z","lastAt":"2008-10-19T07:07:12Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93415","messageId":"7vzll16p27.fsf@gitster.siamese.dyndns.org","threadId":"15962","inReplyTo":null,"subject":"[PATCH/RFR&A] gitweb: Better processing format string in custom links in navbar","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-19T07:07:12Z","receivedAt":"2008-10-19T07:07:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I was not around when this was posted and discussed; Shawn's note says\nthis is waiting for \"some sort of response from Pasky\", hence this request\nfor review and ack.  It still is parked in 'pu'.\n\n-- >8 --\n\nMake processing format string in custom links in action bar ('actions'\nfeature) more robust.  Now there would be no problems if one of\nexpanded values (for example project name, of project filename)\ncontains '%'; additionally format string supports '%' escaping by\ndoubling, i.e. '%%' expands to '%'.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n gitweb/gitweb.perl |   19 ++++++++++++-------\n 1 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1116800..cc6edbe 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -290,10 +290,10 @@ our %feature = (\n \n \t# The 'default' value consists of a list of triplets in the form\n \t# (label, link, position) where position is the label after which\n-\t# to inster the link and link is a format string where %n expands\n+\t# to insert the link and link is a format string where %n expands\n \t# to the project name, %f to the project path within the filesystem,\n \t# %h to the current hash (h gitweb parameter) and %b to the current\n-\t# hash base (hb gitweb parameter).\n+\t# hash base (hb gitweb parameter); %% expands to %.\n \n \t# To enable system wide have in $GITWEB_CONFIG e.g.\n \t# $feature{'actions'}{'default'} = [('graphiclog',\n@@ -2866,14 +2866,19 @@ sub git_print_page_nav {\n \t$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;\n \n \tmy @actions = gitweb_check_feature('actions');\n+\tmy %repl = (\n+\t\t'%' => '%',\n+\t\t'n' => $project,         # project name\n+\t\t'f' => $git_dir,         # project path within filesystem\n+\t\t'h' => $treehead || '',  # current hash ('h' parameter)\n+\t\t'b' => $treebase || '',  # hash base ('hb' parameter)\n+\t);\n \twhile (@actions) {\n-\t\tmy ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));\n+\t\tmy ($label, $link, $pos) = splice(@actions,0,3);\n+\t\t# insert\n \t\t@navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;\n \t\t# munch munch\n-\t\t$link =~ s#%n#$project#g;\n-\t\t$link =~ s#%f#$git_dir#g;\n-\t\t$treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;\n-\t\t$treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;\n+\t\t$link =~ s/%([%nfhb])/$repl{$1}/g;\n \t\t$arg{$label}{'_href'} = $link;\n \t}\n \n-- \n1.6.0.2.767.g8f0e\n"}]}