X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/e1b1b313dafdcd31e7e6487d603a80213a7f9db36f1e2c35883ada10bd62ccfe..4acee97a71be7c3482ad779eacf3a9d5773a59540b344cc3f4ba4590f97f6bdd:/gitweb.perl
diff --git a/gitweb.perl b/gitweb.perl
index b25d638..ae4fd99 100755
--- a/gitweb.perl
+++ b/gitweb.perl
@@ -847,6 +847,23 @@ sub chop_str {
return "$body$tail";
}
+# takes the same arguments as chop_str, but also wraps a around the
+# result with a title attribute if it does get chopped. Additionally, the
+# string is HTML-escaped.
+sub chop_and_escape_str {
+ my $str = shift;
+ my $len = shift;
+ my $add_len = shift || 10;
+
+ my $chopped = chop_str($str, $len, $add_len);
+ if ($chopped eq $str) {
+ return esc_html($chopped);
+ } else {
+ return qq{} .
+ esc_html($chopped) . qq{};
+ }
+}
+
## ----------------------------------------------------------------------
## functions returning short strings
@@ -3396,7 +3413,7 @@ sub git_project_list_body {
"
" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
-class => "list", -title => $pr->{'descr_long'}},
esc_html($pr->{'descr'})) . " | \n" .
- "" . esc_html(chop_str($pr->{'owner'}, 15)) . " | \n";
+ "" . chop_and_escape_str($pr->{'owner'}, 15) . " | \n";
print "{'age'}) . "\">" .
(defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . " | \n" .
"" .
@@ -3438,12 +3455,7 @@ sub git_shortlog_body {
print " | \n";
}
$alternate ^= 1;
- my $author = chop_str($co{'author_name'}, 10);
- if ($author ne $co{'author_name'}) {
- $author = "" . esc_html($author) . "";
- } else {
- $author = esc_html($author);
- }
+ my $author = chop_and_escape_str($co{'author_name'}, 10);
# git_summary() used print "| $co{'age_string'} | \n" .
print "$co{'age_string_date'} | \n" .
"" . $author . " | \n" .
@@ -3495,12 +3507,7 @@ sub git_history_body {
}
$alternate ^= 1;
# shortlog uses chop_str($co{'author_name'}, 10)
- my $author = chop_str($co{'author_name'}, 15, 3);
- if ($author ne $co{'author_name'}) {
- "" . esc_html($author) . "";
- } else {
- $author = esc_html($author);
- }
+ my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
print "$co{'age_string_date'} | \n" .
"" . $author . " | \n" .
"";
@@ -3656,17 +3663,12 @@ sub git_search_grep_body {
print " |
\n";
}
$alternate ^= 1;
- my $author = chop_str($co{'author_name'}, 15, 5);
- if ($author ne $co{'author_name'}) {
- $author = "" . esc_html($author) . "";
- } else {
- $author = esc_html($author);
- }
+ my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
print "| $co{'age_string_date'} | \n" .
"" . $author . " | \n" .
"" .
$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
- esc_html(chop_str($co{'title'}, 50)) . " ");
+ chop_and_escape_str($co{'title'}, 50) . " ");
my $comment = $co{'comment'};
foreach my $line (@$comment) {
if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
@@ -5176,18 +5178,13 @@ sub git_search {
print " |
\n";
}
$alternate ^= 1;
- my $author = chop_str($co{'author_name'}, 15, 5);
- if ($author ne $co{'author_name'}) {
- $author = "" . esc_html($author) . "";
- } else {
- $author = esc_html($author);
- }
+ my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
print "| $co{'age_string_date'} | \n" .
"" . $author . " | \n" .
"" .
$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
-class => "list subject"},
- esc_html(chop_str($co{'title'}, 50)) . " ");
+ chop_and_escape_str($co{'title'}, 50) . " ");
while (my $setref = shift @files) {
my %set = %$setref;
print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
|