From e076a0e71f25430205d0437c177fd12a7018e5ad Mon Sep 17 00:00:00 2001 From: David Symonds Date: Mon, 22 Oct 2007 10:28:03 +1000 Subject: [PATCH 1/3] gitweb: Provide title attributes for abbreviated author names. Signed-off-by: David Symonds Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 48e21dad6c..0d45769bc3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3437,9 +3437,15 @@ 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); + } # git_summary() used print "$co{'age_string'}\n" . print "$co{'age_string_date'}\n" . - "" . esc_html(chop_str($co{'author_name'}, 10)) . "\n" . + "" . $author . "\n" . ""; print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref); @@ -3487,9 +3493,15 @@ sub git_history_body { print "\n"; } $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); + } print "$co{'age_string_date'}\n" . - # shortlog uses chop_str($co{'author_name'}, 10) - "" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "\n" . + "" . $author . "\n" . ""; # originally git_history used chop_str($co{'title'}, 50) print format_subject_html($co{'title'}, $co{'title_short'}, @@ -3643,8 +3655,14 @@ 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); + } print "$co{'age_string_date'}\n" . - "" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "\n" . + "" . $author . "\n" . "" . $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, esc_html(chop_str($co{'title'}, 50)) . "
"); @@ -5157,8 +5175,14 @@ 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); + } print "$co{'age_string_date'}\n" . - "" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "\n" . + "" . $author . "\n" . "" . $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, From ce58ec9158fe398dc7142e34cf575d336f408370 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Tue, 23 Oct 2007 11:31:22 +1000 Subject: [PATCH 2/3] gitweb: Refactor abbreviation-with-title-attribute code. Signed-off-by: David Symonds Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0d45769bc3..818783eba4 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -846,6 +846,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 @@ -3437,12 +3454,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" . @@ -3494,12 +3506,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" . ""; @@ -3655,12 +3662,7 @@ 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" . "" . @@ -5175,12 +5177,7 @@ 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" . "" . From d3cd249565b6457d5845e7396530db7685a970bb Mon Sep 17 00:00:00 2001 From: David Symonds Date: Tue, 23 Oct 2007 11:31:23 +1000 Subject: [PATCH 3/3] gitweb: Use chop_and_escape_str in more places. Signed-off-by: David Symonds Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 818783eba4..8916950694 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3412,7 +3412,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" . "" . @@ -3667,7 +3667,7 @@ sub git_search_grep_body { "" . $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) { @@ -5183,7 +5183,7 @@ sub git_search { "" . $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'},