From: kiko%async.com.br <> Date: Fri, 6 Aug 2004 05:19:21 +0000 (+0000) Subject: Branch fix for bug 253604 When commit a bug, errors in the validation X-Git-Tag: bugzilla-2.18rc3~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5b0c2a2323b5d5eed276f0f3b3ec5c0569b4e46;p=thirdparty%2Fbugzilla.git Branch fix for bug 253604 When commit a bug, errors in the validation must appear before user match. Moves time validation to the validation section in process_bug.cgi. Backported Bugzilla::Bug::ValidateTime to get this to work on branch. Patch by Tiago R. Mello , r=joel, vladd; a218=justdave. --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 20c131e227..919c726de4 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -491,6 +491,13 @@ sub EmitDependList { return @list; } +sub ValidateTime { + my ($time, $field) = @_; + if ($time > 99999.99 || $time < 0 || !($time =~ /^(?:\d+(?:\.\d*)?|\.\d+)$/)) { + &::ThrowUserError("need_positive_number", {field => "$field"}, "abort"); + } +} + sub AUTOLOAD { use vars qw($AUTOLOAD); my $attr = $AUTOLOAD; diff --git a/process_bug.cgi b/process_bug.cgi index d759aa8dbd..5869a0363d 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -91,6 +91,16 @@ if (defined $::FORM{'id'}) { # Make sure there are bugs to process. scalar(@idlist) || ThrowUserError("no_bugs_chosen"); +# Validate all timetracking fields +foreach my $field ("estimated_time", "work_time", "remaining_time") { + if (defined $::FORM{$field}) { + my $er_time = trim($::FORM{$field}); + if ($er_time ne $::FORM{'dontchange'}) { + Bugzilla::Bug::ValidateTime($er_time, $field); + } + } +} + # do a match on the fields if applicable # The order of these function calls is important, as both Flag::validate @@ -773,16 +783,8 @@ if (UserInGroup(Param('timetrackinggroup'))) { if (defined $::FORM{$field}) { my $er_time = trim($::FORM{$field}); if ($er_time ne $::FORM{'dontchange'}) { - if ($er_time > 99999.99) { - ThrowUserError("value_out_of_range", {field => $field}); - } - if ($er_time =~ /^(?:\d+(?:\.\d*)?|\.\d+)$/) { - DoComma(); - $::query .= "$field = " . SqlQuote($er_time); - } else { - ThrowUserError("need_positive_number", - {field => $field}); - } + DoComma(); + $::query .= "$field = " . SqlQuote($er_time); } } } @@ -1282,9 +1284,6 @@ foreach my $id (@idlist) { delete $::FORM{'work_time'} unless UserInGroup(Param('timetrackinggroup')); - if ($::FORM{'work_time'} && $::FORM{'work_time'} > 99999.99) { - ThrowUserError("value_out_of_range", {field => 'work_time'}); - } if ($::FORM{'comment'} || $::FORM{'work_time'}) { if ($::FORM{'work_time'} && (!defined $::FORM{'comment'} || $::FORM{'comment'} =~ /^\s*$/)) {