@matheusbsbs / matheus-bagliano / commits / 2b11e059ee
Fork 0

gitweb: Better processing format string in custom links in navbar

Make processing format string in custom links in action bar ('actions' feature) more robust. Now there would be no problems if one of expanded values (for example project name, of project filename) contains '%'; additionally format string supports '%' escaping by doubling, i.e. '%%' expands to '%'. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Jakub Narebski committed Oct 12, 2008 at 00:02 UTC 2b11e059ee55ae7fb9913acf84fcc065e3e33287
1 file changed +12 -7
gitweb/gitweb.perl
+12 -7
@@ -290,10 +290,10 @@ our %feature = (
290
291 # The 'default' value consists of a list of triplets in the form
292 # (label, link, position) where position is the label after which
293 - # to inster the link and link is a format string where %n expands
293 + # to insert the link and link is a format string where %n expands
294 # to the project name, %f to the project path within the filesystem,
295 # %h to the current hash (h gitweb parameter) and %b to the current
296 - # hash base (hb gitweb parameter).
296 + # hash base (hb gitweb parameter); %% expands to %.
297
298 # To enable system wide have in $GITWEB_CONFIG e.g.
299 # $feature{'actions'}{'default'} = [('graphiclog',
@@ -2866,14 +2866,19 @@ sub git_print_page_nav {
2866 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2867
2868 my @actions = gitweb_check_feature('actions');
2869 + my %repl = (
2870 + '%' => '%',
2871 + 'n' => $project, # project name
2872 + 'f' => $git_dir, # project path within filesystem
2873 + 'h' => $treehead || '', # current hash ('h' parameter)
2874 + 'b' => $treebase || '', # hash base ('hb' parameter)
2875 + );
2876 while (@actions) {
2870 - my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2877 + my ($label, $link, $pos) = splice(@actions,0,3);
2878 + # insert
2879 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2880 # munch munch
2873 - $link =~ s#%n#$project#g;
2874 - $link =~ s#%f#$git_dir#g;
2875 - $treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
2876 - $treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
2881 + $link =~ s/%([%nfhb])/$repl{$1}/g;
2882 $arg{$label}{'_href'} = $link;
2883 }
2884