From aef5cb18c3f2f6e1a438faed08e944af9db4847c Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Sun, 18 Jul 2010 02:12:27 -0700 Subject: Bug 579695: Make xt/search.t do substring tests using a more consistent substring length, thus fixing an intermittent failure that would show up when searching the cf_multi_select field. r=mkanat, a=mkanat (module owner) --- xt/lib/Bugzilla/Test/Search/FieldTest.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'xt/lib/Bugzilla/Test/Search/FieldTest.pm') diff --git a/xt/lib/Bugzilla/Test/Search/FieldTest.pm b/xt/lib/Bugzilla/Test/Search/FieldTest.pm index f8186c5b3..b5f6d2334 100644 --- a/xt/lib/Bugzilla/Test/Search/FieldTest.pm +++ b/xt/lib/Bugzilla/Test/Search/FieldTest.pm @@ -461,13 +461,27 @@ sub _translate_value_for_bug { sub _substr_value { my ($self, $value) = @_; my $field = $self->field; + my $type = $self->field_object->type; my $substr_size = SUBSTR_SIZE; if (exists FIELD_SUBSTR_SIZE->{$field}) { $substr_size = FIELD_SUBSTR_SIZE->{$field}; } - + elsif (exists FIELD_SUBSTR_SIZE->{$type}) { + $substr_size = FIELD_SUBSTR_SIZE->{$type}; + } if ($substr_size > 0) { - return substr($value, 0, $substr_size); + # The field name is included in every field value, and if it's + # long, it might take up the whole substring, and we don't want that. + if (!grep { $_ eq $field or $_ eq $type } SUBSTR_NO_FIELD_ADD) { + $substr_size += length($field); + } + my $string = substr($value, 0, $substr_size); + # Make percentage_complete substrings strings match integers uniquely, + # by searching for the full decimal number. + if ($field eq 'percentage_complete' and length($string) < $substr_size) { + $string .= ".000"; + } + return $string; } return substr($value, $substr_size); } -- cgit v1.2.3-24-g4f1b