Commit 8f405c09 authored by Albert Ting's avatar Albert Ting Committed by Dylan Hardison

Bug 688205 - quoted text inside comments should wrap

r=dylan,a=dylan
parent 85ca54b4
...@@ -272,6 +272,9 @@ sub body_full { ...@@ -272,6 +272,9 @@ sub body_full {
else { else {
$body = $self->body; $body = $self->body;
} }
if (!$self->is_markdown and !$self->already_wrapped) {
$body = wrap_cite($body);
}
if ($params->{wrap} and !$self->already_wrapped) { if ($params->{wrap} and !$self->already_wrapped) {
$body = wrap_comment($body); $body = wrap_comment($body);
} }
......
...@@ -972,6 +972,13 @@ sub create { ...@@ -972,6 +972,13 @@ sub create {
return sub { wrap_comment($_[0], $cols) } return sub { wrap_comment($_[0], $cols) }
}, 1], }, 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 # We force filtering of every variable in key security-critical
# places; we have a none filter for people to use when they # places; we have a none filter for people to use when they
# really, really don't want a variable to be changed. # really, really don't want a variable to be changed.
......
...@@ -18,7 +18,7 @@ use parent qw(Exporter); ...@@ -18,7 +18,7 @@ use parent qw(Exporter);
i_am_cgi i_am_webservice correct_urlbase remote_ip i_am_cgi i_am_webservice correct_urlbase remote_ip
validate_ip do_ssl_redirect_if_required use_attachbase validate_ip do_ssl_redirect_if_required use_attachbase
diff_arrays on_main_db 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 format_time validate_date validate_time datetime_from
is_7bit_clean bz_crypt generate_random_password is_7bit_clean bz_crypt generate_random_password
validate_email_syntax check_email_syntax clean_text validate_email_syntax check_email_syntax clean_text
...@@ -456,6 +456,27 @@ sub wrap_comment { ...@@ -456,6 +456,27 @@ sub wrap_comment {
return $wrappedcomment; 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 { sub find_wrap_point {
my ($string, $maxpos) = @_; my ($string, $maxpos) = @_;
if (!$string) { return 0 } if (!$string) { return 0 }
...@@ -1244,4 +1265,6 @@ if Bugzilla is currently using the shadowdb or not. Used like: ...@@ -1244,4 +1265,6 @@ if Bugzilla is currently using the shadowdb or not. Used like:
=item display_value =item display_value
=item wrap_cite
=back =back
...@@ -342,9 +342,10 @@ sub render_comment { ...@@ -342,9 +342,10 @@ sub render_comment {
Bugzilla->switch_to_shadow_db(); Bugzilla->switch_to_shadow_db();
my $bug = $params->{id} ? Bugzilla::Bug->check($params->{id}) : undef; my $bug = $params->{id} ? Bugzilla::Bug->check($params->{id}) : undef;
my $markdown = $params->{markdown} ? 1 : 0; my $tmpl
my $tmpl = $markdown ? '[% text FILTER markdown(bug, { is_markdown => 1 }) %]' : '[% text FILTER markdown(bug) %]'; = $params->{markdown}
? '[% text FILTER markdown(bug, { is_markdown => 1 }) %]'
: '[% text FILTER wrap_cite FILTER markdown(bug) %]';
my $html; my $html;
my $template = Bugzilla->template; my $template = Bugzilla->template;
$template->process( $template->process(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment