]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 688205 - quoted text inside comments should wrap
authorAlbert Ting <altlist@gmail.com>
Sat, 2 Jan 2016 21:20:22 +0000 (16:20 -0500)
committerDylan Hardison <dylan@mozilla.com>
Sat, 2 Jan 2016 21:21:04 +0000 (16:21 -0500)
r=dylan,a=dylan

Bugzilla/Comment.pm
Bugzilla/Template.pm
Bugzilla/Util.pm
Bugzilla/WebService/Bug.pm

index 8232f5ac100ff3402d652c4e4fe083268fe2619d..7d7ac0d804c0f9160979039be5aa164968861e02 100644 (file)
@@ -272,6 +272,9 @@ sub body_full {
     else {
         $body = $self->body;
     }
+    if (!$self->is_markdown and !$self->already_wrapped) {
+        $body = wrap_cite($body);
+    }
     if ($params->{wrap} and !$self->already_wrapped) {
         $body = wrap_comment($body);
     }
index 9398ca4b51609018b22c730b6dc25f5df31676e3..3cbff4733f113f39712918f2d3e6cb1a4341d8aa 100644 (file)
@@ -972,6 +972,13 @@ sub create {
                     return sub { wrap_comment($_[0], $cols) }
                 }, 1],
 
+            # Wrap cited text
+            wrap_cite => [
+                sub {
+                    my ($context, $cols) = @_;
+                    return sub { wrap_cite($_[0], $cols) }
+                }, 1],
+
             # We force filtering of every variable in key security-critical
             # places; we have a none filter for people to use when they 
             # really, really don't want a variable to be changed.
index ad008b768a748bafb4ae2f75ae5a49c670c1df8b..c28c0d05dfd93b342a60747aecaa0381ef17063e 100644 (file)
@@ -18,7 +18,7 @@ use parent qw(Exporter);
                              i_am_cgi i_am_webservice correct_urlbase remote_ip
                              validate_ip do_ssl_redirect_if_required use_attachbase
                              diff_arrays on_main_db
-                             trim wrap_hard wrap_comment find_wrap_point
+                             trim wrap_hard wrap_comment find_wrap_point wrap_cite
                              format_time validate_date validate_time datetime_from
                              is_7bit_clean bz_crypt generate_random_password
                              validate_email_syntax check_email_syntax clean_text
@@ -456,6 +456,27 @@ sub wrap_comment {
     return $wrappedcomment;
 }
 
+sub wrap_cite {
+    my ($comment, $cols) = @_;
+    my $wrappedcomment = "";
+
+    # Use 'local', as recommended by Text::Wrap's perldoc.
+    local $Text::Wrap::columns = $cols || COMMENT_COLS;
+    # Make words that are longer than COMMENT_COLS not wrap.
+    local $Text::Wrap::huge    = 'overflow';
+    # Don't mess with tabs.
+    local $Text::Wrap::unexpand = 0;
+
+    foreach my $line (split(/\r\n|\r|\n/, $comment)) {
+      if ($line =~ /^(>+ *)/) {
+        $wrappedcomment .= wrap('', $1, $line) . "\n";
+      } else {
+        $wrappedcomment .= $line . "\n";
+      }
+    }
+    return $wrappedcomment;
+}
+
 sub find_wrap_point {
     my ($string, $maxpos) = @_;
     if (!$string) { return 0 }
@@ -1244,4 +1265,6 @@ if Bugzilla is currently using the shadowdb or not. Used like:
 
 =item display_value
 
+=item wrap_cite
+
 =back
index 84f209347027d6295cd02441917524f8f9e086b4..cc40259f86aad331de75e48880d0e94fb9d75a87 100644 (file)
@@ -342,9 +342,10 @@ sub render_comment {
     Bugzilla->switch_to_shadow_db();
     my $bug = $params->{id} ? Bugzilla::Bug->check($params->{id}) : undef;
 
-    my $markdown = $params->{markdown} ? 1 : 0;
-    my $tmpl = $markdown ? '[% text FILTER markdown(bug, { is_markdown => 1 }) %]' : '[% text FILTER markdown(bug) %]';
-
+    my $tmpl
+      = $params->{markdown}
+      ? '[% text FILTER markdown(bug, { is_markdown => 1 }) %]'
+      : '[% text FILTER wrap_cite FILTER markdown(bug) %]';
     my $html;
     my $template = Bugzilla->template;
     $template->process(