Skip to content

Commit 2b11e05

Browse files
jnarebspearce
authored andcommitted
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>
1 parent 5c283eb commit 2b11e05

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

gitweb/gitweb.perl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ BEGIN
290290

291291
# The 'default' value consists of a list of triplets in the form
292292
# (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
294294
# to the project name, %f to the project path within the filesystem,
295295
# %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 %.
297297

298298
# To enable system wide have in $GITWEB_CONFIG e.g.
299299
# $feature{'actions'}{'default'} = [('graphiclog',
@@ -2866,14 +2866,19 @@ sub git_print_page_nav {
28662866
$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
28672867

28682868
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+
);
28692876
while (@actions) {
2870-
my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2877+
my ($label, $link, $pos) = splice(@actions,0,3);
2878+
# insert
28712879
@navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
28722880
# 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;
28772882
$arg{$label}{'_href'} = $link;
28782883
}
28792884

0 commit comments

Comments
 (0)