Commit 0e2ea68e authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 411437: Clipping of "Free Text" fields when user enters more then 255…

Bug 411437: Clipping of "Free Text" fields when user enters more then 255 characters - Patch by Fré©ric Buclin <LpSolit@gmail.com> r/a=mkanat
parent a404e6c3
...@@ -148,9 +148,12 @@ sub VALIDATORS { ...@@ -148,9 +148,12 @@ sub VALIDATORS {
elsif ($field->type == FIELD_TYPE_DATETIME) { elsif ($field->type == FIELD_TYPE_DATETIME) {
$validator = \&_check_datetime_field; $validator = \&_check_datetime_field;
} }
else { elsif ($field->type == FIELD_TYPE_FREETEXT) {
$validator = \&_check_freetext_field; $validator = \&_check_freetext_field;
} }
else {
$validator = \&_check_default_field;
}
$validators->{$field->name} = $validator; $validators->{$field->name} = $validator;
} }
...@@ -1074,8 +1077,6 @@ sub _check_estimated_time { ...@@ -1074,8 +1077,6 @@ sub _check_estimated_time {
return $_[0]->_check_time($_[1], 'estimated_time'); return $_[0]->_check_time($_[1], 'estimated_time');
} }
sub _check_freetext_field { return defined $_[1] ? trim($_[1]) : ''; }
sub _check_groups { sub _check_groups {
my ($invocant, $product, $group_ids) = @_; my ($invocant, $product, $group_ids) = @_;
...@@ -1373,6 +1374,18 @@ sub _check_datetime_field { ...@@ -1373,6 +1374,18 @@ sub _check_datetime_field {
return $date_time return $date_time
} }
sub _check_default_field { return defined $_[1] ? trim($_[1]) : ''; }
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_multi_select_field { sub _check_multi_select_field {
my ($invocant, $values, $field) = @_; my ($invocant, $values, $field) = @_;
return [] if !$values; return [] if !$values;
......
...@@ -149,6 +149,7 @@ use File::Basename; ...@@ -149,6 +149,7 @@ use File::Basename;
MAX_LEN_QUERY_NAME MAX_LEN_QUERY_NAME
MAX_MILESTONE_SIZE MAX_MILESTONE_SIZE
MAX_COMPONENT_SIZE MAX_COMPONENT_SIZE
MAX_FREETEXT_LENGTH
); );
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes); @Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
...@@ -423,6 +424,9 @@ use constant MAX_MILESTONE_SIZE => 20; ...@@ -423,6 +424,9 @@ use constant MAX_MILESTONE_SIZE => 20;
# The longest component name allowed. # The longest component name allowed.
use constant MAX_COMPONENT_SIZE => 64; use constant MAX_COMPONENT_SIZE => 64;
# Maximum length allowed for free text fields.
use constant MAX_FREETEXT_LENGTH => 255;
sub bz_locations { sub bz_locations {
# We know that Bugzilla/Constants.pm must be in %INC at this point. # 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 # So the only question is, what's the name of the directory
......
...@@ -473,8 +473,8 @@ for more details. ...@@ -473,8 +473,8 @@ for more details.
=item 104 (Invalid Field) =item 104 (Invalid Field)
One of the drop-down fields has an invalid value. The error message will One of the drop-down fields has an invalid value, or a value entered in a
have more detail. text field is too long. The error message will have more detail.
=item 105 (Invalid Component) =item 105 (Invalid Component)
......
...@@ -65,6 +65,7 @@ use constant WS_ERROR_CODE => { ...@@ -65,6 +65,7 @@ use constant WS_ERROR_CODE => {
alias_has_comma_or_space => 103, alias_has_comma_or_space => 103,
# Misc. bug field errors # Misc. bug field errors
illegal_field => 104, illegal_field => 104,
freetext_too_long => 104,
# Component errors # Component errors
require_component => 105, require_component => 105,
component_name_too_long => 105, component_name_too_long => 105,
......
...@@ -41,8 +41,9 @@ ...@@ -41,8 +41,9 @@
[% IF editable %] [% IF editable %]
[% SWITCH field.type %] [% SWITCH field.type %]
[% CASE constants.FIELD_TYPE_FREETEXT %] [% CASE constants.FIELD_TYPE_FREETEXT %]
<input name="[% field.name FILTER html %]" <input id="[% field.name FILTER html %]" name="[% field.name FILTER html %]"
value="[% value FILTER html %]" size="60"> value="[% value FILTER html %]" size="60"
maxlength="[% constants.MAX_FREETEXT_LENGTH FILTER none %]">
[% CASE constants.FIELD_TYPE_DATETIME %] [% CASE constants.FIELD_TYPE_DATETIME %]
<input name="[% field.name FILTER html %]" size="20" <input name="[% field.name FILTER html %]" size="20"
id="[% field.name FILTER html %]" id="[% field.name FILTER html %]"
......
...@@ -592,6 +592,13 @@ ...@@ -592,6 +592,13 @@
The sort key must be an integer between 0 and 32767 inclusive. The sort key must be an integer between 0 and 32767 inclusive.
It cannot be <em>[% sortkey FILTER html %]</em>. It cannot be <em>[% sortkey FILTER html %]</em>.
[% ELSIF error == "freetext_too_long" %]
[% title = "Text Too Long" %]
The text you entered is too long ([% text.length FILTER html %] characters,
above the maximum length allowed of [% constants.MAX_FREETEXT_LENGTH FILTER none %]
characters):
<p><em>[% text FILTER html %]</em></p>
[% ELSIF error == "group_cannot_delete" %] [% ELSIF error == "group_cannot_delete" %]
[% title = "Cannot Delete Group" %] [% title = "Cannot Delete Group" %]
The <em>[% name FILTER html %]</em> group cannot be deleted because The <em>[% name FILTER html %]</em> group cannot be deleted because
......
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