Commit fcd963fc authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 272623: FindWrapPoint is misplaced in process_bug.cgi - Patch by Frédéric…

Bug 272623: FindWrapPoint is misplaced in process_bug.cgi - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=myk
parent 6d044219
...@@ -33,8 +33,8 @@ use base qw(Exporter); ...@@ -33,8 +33,8 @@ use base qw(Exporter);
html_quote url_quote value_quote xml_quote html_quote url_quote value_quote xml_quote
css_class_quote css_class_quote
lsearch max min lsearch max min
diff_arrays diff_arrays diff_strings
trim diff_strings wrap_comment trim wrap_comment find_wrap_point
format_time format_time_decimal format_time format_time_decimal
file_mod_time); file_mod_time);
...@@ -219,6 +219,25 @@ sub wrap_comment ($) { ...@@ -219,6 +219,25 @@ sub wrap_comment ($) {
return $wrappedcomment; return $wrappedcomment;
} }
sub find_wrap_point ($$) {
my ($string, $maxpos) = @_;
if (!$string) { return 0 }
if (length($string) < $maxpos) { return length($string) }
my $wrappoint = rindex($string, ",", $maxpos); # look for comma
if ($wrappoint < 0) { # can't find comma
$wrappoint = rindex($string, " ", $maxpos); # look for space
if ($wrappoint < 0) { # can't find space
$wrappoint = rindex($string, "-", $maxpos); # look for hyphen
if ($wrappoint < 0) { # can't find hyphen
$wrappoint = $maxpos; # just truncate it
} else {
$wrappoint++; # leave hyphen on the left side
}
}
}
return $wrappoint;
}
sub format_time { sub format_time {
my ($time) = @_; my ($time) = @_;
...@@ -480,6 +499,14 @@ database. ...@@ -480,6 +499,14 @@ database.
=back =back
=item C<find_wrap_point($string, $maxpos)>
Search for a comma, a whitespace or a hyphen to split $string, within the first
$maxpos characters. If none of them is found, just split $string at $maxpos.
The search starts at $maxpos and goes back to the beginning of the string.
=back
=head2 Formatting Time =head2 Formatting Time
=over 4 =over 4
......
...@@ -48,6 +48,10 @@ use Bugzilla::BugMail; ...@@ -48,6 +48,10 @@ use Bugzilla::BugMail;
use Bugzilla::Bug; use Bugzilla::Bug;
use Bugzilla::User; use Bugzilla::User;
# Used in LogActivityEntry(). Gives the max length of lines in the
# activity table.
use constant MAX_LINE_LENGTH => 254;
# Shut up misguided -w warnings about "used only once". For some reason, # Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here. # "use vars" chokes on me when I try it here.
...@@ -254,16 +258,16 @@ sub LogActivityEntry { ...@@ -254,16 +258,16 @@ sub LogActivityEntry {
# into multiple entries if it's too long. # into multiple entries if it's too long.
while ($removed || $added) { while ($removed || $added) {
my ($removestr, $addstr) = ($removed, $added); my ($removestr, $addstr) = ($removed, $added);
if (length($removestr) > 254) { if (length($removestr) > MAX_LINE_LENGTH) {
my $commaposition = FindWrapPoint($removed, 254); my $commaposition = find_wrap_point($removed, MAX_LINE_LENGTH);
$removestr = substr($removed,0,$commaposition); $removestr = substr($removed,0,$commaposition);
$removed = substr($removed,$commaposition); $removed = substr($removed,$commaposition);
$removed =~ s/^[,\s]+//; # remove any comma or space $removed =~ s/^[,\s]+//; # remove any comma or space
} else { } else {
$removed = ""; # no more entries $removed = ""; # no more entries
} }
if (length($addstr) > 254) { if (length($addstr) > MAX_LINE_LENGTH) {
my $commaposition = FindWrapPoint($added, 254); my $commaposition = find_wrap_point($added, MAX_LINE_LENGTH);
$addstr = substr($added,0,$commaposition); $addstr = substr($added,0,$commaposition);
$added = substr($added,$commaposition); $added = substr($added,$commaposition);
$added =~ s/^[,\s]+//; # remove any comma or space $added =~ s/^[,\s]+//; # remove any comma or space
......
...@@ -1151,25 +1151,6 @@ sub SnapShotDeps { ...@@ -1151,25 +1151,6 @@ sub SnapShotDeps {
my $timestamp; my $timestamp;
my $bug_changed; my $bug_changed;
sub FindWrapPoint {
my ($string, $startpos) = @_;
if (!$string) { return 0 }
if (length($string) < $startpos) { return length($string) }
my $wrappoint = rindex($string, ",", $startpos); # look for comma
if ($wrappoint < 0) { # can't find comma
$wrappoint = rindex($string, " ", $startpos); # look for space
if ($wrappoint < 0) { # can't find space
$wrappoint = rindex($string, "-", $startpos); # look for hyphen
if ($wrappoint < 0) { # can't find hyphen
$wrappoint = $startpos; # just truncate it
} else {
$wrappoint++; # leave hyphen on the left side
}
}
}
return $wrappoint;
}
sub LogDependencyActivity { sub LogDependencyActivity {
my ($i, $oldstr, $target, $me, $timestamp) = (@_); my ($i, $oldstr, $target, $me, $timestamp) = (@_);
my $sql_timestamp = SqlQuote($timestamp); my $sql_timestamp = SqlQuote($timestamp);
......
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