Currently, a site administrator must choose between allowing all or none of a committag's options to be overridden in the project config. However, a site admin may wish to permit specifying a bugzilla URL without risking a maliciously resource hungry regular expression. Allow the site admin to specify which committag parameters may be overridden. Preserve the behavior of the original 0 and 1 override specifications. Signed-off-by: Marcel M. Cary <marcel@xxxxxxxxxxxxxxxx> --- gitweb/INSTALL | 8 +++++++- gitweb/gitweb.perl | 24 ++++++++++++++++++------ t/t9502-gitweb-committags.sh | 13 +++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/gitweb/INSTALL b/gitweb/INSTALL index 9081ed8..15c0128 100644 --- a/gitweb/INSTALL +++ b/gitweb/INSTALL @@ -133,9 +133,15 @@ adding the following lines to your $GITWEB_CONFIG: $known_snapshot_formats{'tgz'}{'compressor'} = ['gzip','-6']; To add a committag to the default list of commit tags, for example to -enable hyperlinking of bug numbers to a bug tracker for all projects: +enable hyperlinking of bug numbers to a bug tracker for all projects, while +allowing each project to choose only the base URL for its bug tracker: push @{$feature{'committags'}{'default'}}, 'bugzilla'; + $committags{"bugzilla"}{"override"} = ["url"]; + +And then let each project configure its bug tracker URL: + + git config gitweb.committag.bugzilla.url 'http://bts.example.com?bug=' Gitweb repositories diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 032b1c5..8f4480e 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -225,11 +225,13 @@ our %avatar_size = ( # will not be processed further. # # For any committag, set the 'override' key to 1 to allow individual -# projects to override entries in the 'options' hash for that tag. -# For example, to match only commit hashes given in lowercase in one -# project, add this to the $GITWEB_CONFIG: +# projects to override any entry in the 'options' hash for that tag. +# Leave 'override' as 0 to disallow all overriding of all entries. +# Set 'override' to an array of 'option' key names to allow overriding +# specific keys. For example, to match only commit hashes given in +# lowercase in one project, add this to the $GITWEB_CONFIG: # -# $committags{'sha1'}{'override'} = 1; +# $committags{'sha1'}{'override'} = 1; # or ["pattern"] # # And in the project's config: # @@ -237,7 +239,8 @@ our %avatar_size = ( # # Some committags have additional options whose interpretation depends # on the implementation of the 'sub' key. The hyperlink_committag -# value appends the first captured group to the 'url' option. +# value appends the first captured group to the 'url' option, for example. +# our %committags = ( # Link Git-style hashes to this gitweb 'sha1' => { @@ -1029,8 +1032,17 @@ sub gitweb_load_project_committags { $project_config{$ctname}{$option} = $raw_config{$key}; } foreach my $ctname (keys(%committags)) { - next if (!$committags{$ctname}{'override'}); + my $override = $committags{$ctname}{'override'}; + next if (!$override); + my $override_keys = undef; + if (ref($override) eq "ARRAY") { + $override_keys = {}; + foreach my $optname (@$override) { + $override_keys->{$optname} = 1; + } + } foreach my $optname (keys %{$project_config{$ctname}}) { + next if ($override_keys && !$override_keys->{$optname}); $committags{$ctname}{'options'}{$optname} = $project_config{$ctname}{$optname}; } diff --git a/t/t9502-gitweb-committags.sh b/t/t9502-gitweb-committags.sh index 718e763..e13ac47 100755 --- a/t/t9502-gitweb-committags.sh +++ b/t/t9502-gitweb-committags.sh @@ -68,6 +68,19 @@ test_expect_success 'bugzilla: url overridden but not permitted' ' test_debug 'cat gitweb.log' test_debug 'grep 1234 gitweb.output' +echo '$committags{"bugzilla"}{"override"} = ["url"];' >> gitweb_config.perl +git config gitweb.committag.bugzilla.url 'http://bts.example.com?bug=' +git config gitweb.committag.bugzilla.pattern 'slow DoS regex' +test_expect_success 'bugzilla: url overridden but regex not permitted' ' + gitweb_run "p=.git;a=commit;h=HEAD" && + grep -F -q \ + "Fixes bug <a class=\"text\" href=\"http://bts.example.com?bug=1234\">1234</a> involving" \ + gitweb.output +' +test_debug 'cat gitweb.log' +test_debug 'grep 1234 gitweb.output' +git config --unset gitweb.committag.bugzilla.pattern + echo '$committags{"bugzilla"}{"override"} = 1;' >> gitweb_config.perl test_expect_success 'bugzilla: url overridden' ' gitweb_run "p=.git;a=commit;h=HEAD" && -- 1.6.4.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html