{"thread":{"id":"15865","subject":"[PATCH] gitweb: Better processing format string in custom links in navbar","startedAt":"2008-10-11T22:02:32Z","lastAt":"2008-10-11T22:02:32Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"92813","messageId":"20081011215456.22315.5977.stgit@localhost.localdomain","threadId":"15865","inReplyTo":null,"subject":"[PATCH] gitweb: Better processing format string in custom links in navbar","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-10-11T22:02:32Z","receivedAt":"2008-10-11T22:02:32Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Make 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>\n---\nNeither of parameters we expand to ($projec, $git_dir, $treehash,\n$treebase) is ensured to have no '%' in the value.  Therefore\nsequential expansion, i.e. expanding one parameter after another could\nlead to error.\n\nAlso there was no way to put '%' on the link; now it is possible\nthanks to '%%' -> '%' expansion.\n\nI have tred to be not too generic; you can check unquote() subroutine\nto see how such more generic function (something like tsprintf_simple)\nshould look like\n\n\nPasky, could you check if it works correctly?\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\n-- \nStacked GIT 0.14.3\ngit version 1.6.0.2\n"}]}