From: David Symonds Date: Tue, 23 Oct 2007 01:31:22 +0000 (+1000) Subject: gitweb: Refactor abbreviation-with-title-attribute code. X-Git-Tag: v1.5.4-rc0~303^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ce58ec9158fe398dc7142e34cf575d336f408370;p=git.git gitweb: Refactor abbreviation-with-title-attribute code. Signed-off-by: David Symonds Signed-off-by: Junio C Hamano --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0d45769bc..818783eba 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" . "" .