diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 3b567a0b819..655e2c98499 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -98,9 +98,10 @@ def cast_value(custom_field, value, customized=nil) if value.blank? nil elsif value.is_a?(Array) - value.map do |v| + casted = value.map do |v| cast_single_value(custom_field, v, customized) - end.sort + end + casted.compact.sort else cast_single_value(custom_field, value, customized) end diff --git a/test/unit/lib/redmine/field_format/version_field_format_test.rb b/test/unit/lib/redmine/field_format/version_field_format_test.rb index 50e0e378645..f7fc72a03f7 100644 --- a/test/unit/lib/redmine/field_format/version_field_format_test.rb +++ b/test/unit/lib/redmine/field_format/version_field_format_test.rb @@ -56,4 +56,11 @@ def test_possible_values_options_should_return_project_versions_with_selected_st assert_equal expected, field.possible_values_options(project).map(&:first) end + + def test_cast_value_should_not_raise_error_when_array_contains_value_casted_to_nil + field = IssueCustomField.new(:field_format => 'version') + assert_nothing_raised do + field.cast_value([1,2, 42]) + end + end end