From 3776f86ebdfb6169a35c525ce6b8363eb0cabbe1 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Thu, 27 Feb 2014 08:33:45 +1000 Subject: Bug 466178 - Add an INTEGER custom field type r=glob, a=justdave --- Bugzilla/Bug.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Bugzilla/Bug.pm') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index dd22426bb..a6347cb2e 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -158,6 +158,9 @@ sub VALIDATORS { elsif ($field->type == FIELD_TYPE_TEXTAREA) { $validator = \&_check_textarea_field; } + elsif ($field->type == FIELD_TYPE_INTEGER) { + $validator = \&_check_integer_field; + } else { $validator = \&_check_default_field; } @@ -2110,6 +2113,27 @@ sub _check_textarea_field { return $text; } +sub _check_integer_field { + my ($invocant, $value, $field) = @_; + $value = defined($value) ? trim($value) : ''; + + if ($value eq '') { + return 0; + } + + my $orig_value = $value; + if (!detaint_signed($value)) { + ThrowUserError("number_not_integer", + {field => $field, num => $orig_value}); + } + elsif ($value > MAX_INT_32) { + ThrowUserError("number_too_large", + {field => $field, num => $orig_value, max_num => MAX_INT_32}); + } + + return $value; +} + sub _check_relationship_loop { # Generates a dependency tree for a given bug. Calls itself recursively # to generate sub-trees for the bug's dependencies. -- cgit v1.2.3-24-g4f1b