]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 411437: Clipping of "Free Text" fields when user enters more then 255 characters...
authorlpsolit%gmail.com <>
Sun, 13 Jan 2008 04:03:01 +0000 (04:03 +0000)
committerlpsolit%gmail.com <>
Sun, 13 Jan 2008 04:03:01 +0000 (04:03 +0000)
Bugzilla/Bug.pm
Bugzilla/Constants.pm
Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Constants.pm
process_bug.cgi
template/en/default/bug/field.html.tmpl
template/en/default/global/user-error.html.tmpl

index 92e7f5bff502d5d6558e52ac5c90e55686e2d4fd..1c3dc99aee3d22d604e21480ea42988f1da542d7 100755 (executable)
@@ -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);
index a227e889c21524cd909295abd15d5961a1f21c37..8180b5df24bcd90ef72aef97698582885caa85c4 100644 (file)
@@ -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
index 14ed2e7fddc7c1ca3fc34b50d71cb52e9418fe84..ba1c01e98910f881037e2a8dbbc5681fb099e02e 100755 (executable)
@@ -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)
 
index 0b73114dfbe6d8c30cb0018c940659bcee192bbe..a9bd9e1a8ad80670af2cc8dbabf328a0f4c093ba 100755 (executable)
@@ -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,
index 0164657eb6be7483c4aad64309bb415b4f930c90..901b8c50f021d85e6005b647d38196155098af77 100755 (executable)
@@ -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);
     }
index 07617f19adfbbb33bce154b5282f71a375046e97..25338d36deb837f86e15f9ac65c8a833043dbaf9 100644 (file)
@@ -42,7 +42,9 @@
 [% IF editable %]
   [% SWITCH field.type %]
     [% CASE constants.FIELD_TYPE_FREETEXT %]
-        <input name="[% field.name FILTER html %]" value="[% value FILTER html %]" size="60">
+        <input id="[% field.name FILTER html %]" name="[% field.name FILTER html %]"
+               value="[% value FILTER html %]" size="60"
+               maxlength="[% constants.MAX_FREETEXT_LENGTH FILTER none %]">
     [% CASE constants.FIELD_TYPE_SINGLE_SELECT %]
         <select id="[% field.name FILTER html %]" name="[% field.name FILTER html %]">
           [% IF allow_dont_change %]
index bbd54bacaccbba2eba9447640088fd9122d2dab8..967cbc193e78e2b005b8823fa3cc1ac327ceeb80 100644 (file)
     The sort key must be an integer between 0 and 32767 inclusive.
     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" %]
     [% title = "Cannot Delete Group" %]
     The <em>[% name FILTER html %]</em> group cannot be deleted because