{"thread":{"id":"10437","subject":"[PATCH 2/2] gitweb: Use chop_and_escape_str in more places.","startedAt":"2007-10-23T01:31:22Z","lastAt":"2007-10-23T01:31:23Z","messageCount":2,"participants":["David Symonds"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"56939","messageId":"1193103083390-git-send-email-dsymonds@gmail.com","threadId":"10437","inReplyTo":null,"subject":"[PATCH 1/2] gitweb: Refactor abbreviation-with-title-attribute code.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-10-23T01:31:22Z","receivedAt":"2007-10-23T01:31:22Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"Signed-off-by: David Symonds <dsymonds@gmail.com>\n---\n gitweb/gitweb.perl |   45 +++++++++++++++++++++------------------------\n 1 files changed, 21 insertions(+), 24 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ea84c75..a835bd1 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -842,6 +842,23 @@ sub chop_str {\n \treturn \"$body$tail\";\n }\n \n+# takes the same arguments as chop_str, but also wraps a <span> around the\n+# result with a title attribute if it does get chopped. Additionally, the\n+# string is HTML-escaped.\n+sub chop_and_escape_str {\n+\tmy $str = shift;\n+\tmy $len = shift;\n+\tmy $add_len = shift || 10;\n+\n+\tmy $chopped = chop_str($str, $len, $add_len);\n+\tif ($chopped eq $str) {\n+\t\treturn esc_html($chopped);\n+\t} else {\n+\t\treturn qq{<span title=\"} . esc_html($str) . qq{\">} .\n+\t\t\tesc_html($chopped) . qq{</span>};\n+\t}\n+}\n+\n ## ----------------------------------------------------------------------\n ## functions returning short strings\n \n@@ -3427,12 +3444,7 @@ sub git_shortlog_body {\n \t\t\tprint \"<tr class=\\\"light\\\">\\n\";\n \t\t}\n \t\t$alternate ^= 1;\n-\t\tmy $author = chop_str($co{'author_name'}, 10);\n-\t\tif ($author ne $co{'author_name'}) {\n-\t\t\t$author = \"<span title=\\\"\" . esc_html($co{'author_name'}) . \"\\\">\" . esc_html($author) . \"</span>\";\n-\t\t} else {\n-\t\t\t$author = esc_html($author);\n-\t\t}\n+\t\tmy $author = chop_and_escape_str($co{'author_name'}, 10);\n \t\t# git_summary() used print \"<td><i>$co{'age_string'}</i></td>\\n\" .\n \t\tprint \"<td title=\\\"$co{'age_string_age'}\\\"><i>$co{'age_string_date'}</i></td>\\n\" .\n \t\t      \"<td><i>\" . $author . \"</i></td>\\n\" .\n@@ -3484,12 +3496,7 @@ sub git_history_body {\n \t\t}\n \t\t$alternate ^= 1;\n \t# shortlog uses      chop_str($co{'author_name'}, 10)\n-\t\tmy $author = chop_str($co{'author_name'}, 15, 3);\n-\t\tif ($author ne $co{'author_name'}) {\n-\t\t\t\"<span title=\\\"\" . esc_html($co{'author_name'}) . \"\\\">\" . esc_html($author) . \"</span>\";\n-\t\t} else {\n-\t\t\t$author = esc_html($author);\n-\t\t}\n+\t\tmy $author = chop_and_escape_str($co{'author_name'}, 15, 3);\n \t\tprint \"<td title=\\\"$co{'age_string_age'}\\\"><i>$co{'age_string_date'}</i></td>\\n\" .\n \t\t      \"<td><i>\" . $author . \"</i></td>\\n\" .\n \t\t      \"<td>\";\n@@ -3645,12 +3652,7 @@ sub git_search_grep_body {\n \t\t\tprint \"<tr class=\\\"light\\\">\\n\";\n \t\t}\n \t\t$alternate ^= 1;\n-\t\tmy $author = chop_str($co{'author_name'}, 15, 5);\n-\t\tif ($author ne $co{'author_name'}) {\n-\t\t\t$author = \"<span title=\\\"\" . esc_html($co{'author_name'}) . \"\\\">\" . esc_html($author) . \"</span>\";\n-\t\t} else {\n-\t\t\t$author = esc_html($author);\n-\t\t}\n+\t\tmy $author = chop_and_escape_str($co{'author_name'}, 15, 5);\n \t\tprint \"<td title=\\\"$co{'age_string_age'}\\\"><i>$co{'age_string_date'}</i></td>\\n\" .\n \t\t      \"<td><i>\" . $author . \"</i></td>\\n\" .\n \t\t      \"<td>\" .\n@@ -5165,12 +5167,7 @@ sub git_search {\n \t\t\t\t\t\tprint \"<tr class=\\\"light\\\">\\n\";\n \t\t\t\t\t}\n \t\t\t\t\t$alternate ^= 1;\n-\t\t\t\t\tmy $author = chop_str($co{'author_name'}, 15, 5);\n-\t\t\t\t\tif ($author ne $co{'author_name'}) {\n-\t\t\t\t\t\t$author = \"<span title=\\\"\" . esc_html($co{'author_name'}) . \"\\\">\" . esc_html($author) . \"</span>\";\n-\t\t\t\t\t} else {\n-\t\t\t\t\t\t$author = esc_html($author);\n-\t\t\t\t\t}\n+\t\t\t\t\tmy $author = chop_and_escape_str($co{'author_name'}, 15, 5);\n \t\t\t\t\tprint \"<td title=\\\"$co{'age_string_age'}\\\"><i>$co{'age_string_date'}</i></td>\\n\" .\n \t\t\t\t\t      \"<td><i>\" . $author . \"</i></td>\\n\" .\n \t\t\t\t\t      \"<td>\" .\n-- \n1.5.3.1\n"},{"id":"56938","messageId":"11931030851501-git-send-email-dsymonds@gmail.com","threadId":"10437","inReplyTo":"1193103083390-git-send-email-dsymonds@gmail.com","subject":"[PATCH 2/2] gitweb: Use chop_and_escape_str in more places.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-10-23T01:31:23Z","receivedAt":"2007-10-23T01:31:23Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"Signed-off-by: David Symonds <dsymonds@gmail.com>\n---\n gitweb/gitweb.perl |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex a835bd1..1b6c823 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3402,7 +3402,7 @@ sub git_project_list_body {\n \t\t      \"<td>\" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>\"summary\"),\n \t\t                        -class => \"list\", -title => $pr->{'descr_long'}},\n \t\t                        esc_html($pr->{'descr'})) . \"</td>\\n\" .\n-\t\t      \"<td><i>\" . esc_html(chop_str($pr->{'owner'}, 15)) . \"</i></td>\\n\";\n+\t\t      \"<td><i>\" . chop_and_escape_str($pr->{'owner'}, 15) . \"</i></td>\\n\";\n \t\tprint \"<td class=\\\"\". age_class($pr->{'age'}) . \"\\\">\" .\n \t\t      (defined $pr->{'age_string'} ? $pr->{'age_string'} : \"No commits\") . \"</td>\\n\" .\n \t\t      \"<td class=\\\"link\\\">\" .\n@@ -3657,7 +3657,7 @@ sub git_search_grep_body {\n \t\t      \"<td><i>\" . $author . \"</i></td>\\n\" .\n \t\t      \"<td>\" .\n \t\t      $cgi->a({-href => href(action=>\"commit\", hash=>$co{'id'}), -class => \"list subject\"},\n-\t\t\t       esc_html(chop_str($co{'title'}, 50)) . \"<br/>\");\n+\t\t\t       chop_and_escape_str($co{'title'}, 50) . \"<br/>\");\n \t\tmy $comment = $co{'comment'};\n \t\tforeach my $line (@$comment) {\n \t\t\tif ($line =~ m/^(.*)($search_regexp)(.*)$/i) {\n@@ -5173,7 +5173,7 @@ sub git_search {\n \t\t\t\t\t      \"<td>\" .\n \t\t\t\t\t      $cgi->a({-href => href(action=>\"commit\", hash=>$co{'id'}),\n \t\t\t\t\t              -class => \"list subject\"},\n-\t\t\t\t\t              esc_html(chop_str($co{'title'}, 50)) . \"<br/>\");\n+\t\t\t\t\t              chop_and_escape_str($co{'title'}, 50) . \"<br/>\");\n \t\t\t\t\twhile (my $setref = shift @files) {\n \t\t\t\t\t\tmy %set = %$setref;\n \t\t\t\t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash_base=>$co{'id'},\n-- \n1.5.3.1\n"}]}