From: lpsolit%gmail.com <> Date: Sun, 13 Jan 2008 04:03:01 +0000 (+0000) Subject: Bug 411437: Clipping of "Free Text" fields when user enters more then 255 characters... X-Git-Tag: bugzilla-3.0.4~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a0e5f06e42d0aa6f43180556df68190735f145;p=thirdparty%2Fbugzilla.git Bug 411437: Clipping of "Free Text" fields when user enters more then 255 characters - Patch by Frédéric Buclin r/a=mkanat --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 92e7f5bff5..1c3dc99aee 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -130,11 +130,17 @@ sub VALIDATORS { status_whiteboard => \&_check_status_whiteboard, }; - my @select_fields = Bugzilla->get_fields({custom => 1, obsolete => 0, - type => FIELD_TYPE_SINGLE_SELECT}); + my @custom_fields = Bugzilla->get_fields({custom => 1, obsolete => 0}); - foreach my $field (@select_fields) { - $validators->{$field->name} = \&_check_select_field; + foreach my $field (@custom_fields) { + my $validator; + if ($field->type == FIELD_TYPE_SINGLE_SELECT) { + $validator = \&_check_select_field; + } + elsif ($field->type == FIELD_TYPE_FREETEXT) { + $validator = \&_check_freetext_field; + } + $validators->{$field->name} = $validator if $validator; } return $validators; }; @@ -825,6 +831,18 @@ sub _check_version { return $version; } +# Custom Field Validators + +sub _check_freetext_field { + my ($invocant, $text) = @_; + + $text = (defined $text) ? trim($text) : ''; + if (length($text) > MAX_FREETEXT_LENGTH) { + ThrowUserError('freetext_too_long', { text => $text }); + } + return $text; +} + sub _check_select_field { my ($invocant, $value, $field) = @_; $value = trim($value); diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index a227e889c2..8180b5df24 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -139,6 +139,7 @@ use File::Basename; SAFE_PROTOCOLS MAX_LEN_QUERY_NAME + MAX_FREETEXT_LENGTH ); @Bugzilla::Constants::EXPORT_OK = qw(contenttypes); @@ -387,6 +388,9 @@ use constant ON_WINDOWS => ($^O =~ /MSWin32/i); # The longest that a saved search name can be. use constant MAX_LEN_QUERY_NAME => 64; +# Maximum length allowed for free text fields. +use constant MAX_FREETEXT_LENGTH => 255; + sub bz_locations { # We know that Bugzilla/Constants.pm must be in %INC at this point. # So the only question is, what's the name of the directory diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 14ed2e7fdd..ba1c01e989 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -438,8 +438,8 @@ for more details. =item 104 (Invalid Field) -One of the drop-down fields has an invalid value. The error message will -have more detail. +One of the drop-down fields has an invalid value, or a value entered in a +text field is too long. The error message will have more detail. =item 105 (Invalid Component) diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 0b73114dfb..a9bd9e1a8a 100755 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -63,6 +63,7 @@ use constant WS_ERROR_CODE => { alias_has_comma_or_space => 103, # Misc. bug field errors illegal_field => 104, + freetext_too_long => 104, # Component errors require_component => 105, component_name_too_long => 105, diff --git a/process_bug.cgi b/process_bug.cgi index 0164657eb6..901b8c50f0 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -877,6 +877,8 @@ foreach my $field (Bugzilla->get_fields({custom => 1, obsolete => 0})) { $::query .= "$fname = ?"; my $value = $cgi->param($fname); check_field($fname, $value) if ($field->type == FIELD_TYPE_SINGLE_SELECT); + $value = Bugzilla::Bug->_check_freetext_field($value) + if ($field->type == FIELD_TYPE_FREETEXT); trick_taint($value); push(@values, $value); } diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 07617f19ad..25338d36de 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -42,7 +42,9 @@ [% IF editable %] [% SWITCH field.type %] [% CASE constants.FIELD_TYPE_FREETEXT %] - + [% CASE constants.FIELD_TYPE_SINGLE_SELECT %]