Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

rescue Date::Error when casting value to Date

Ivan Kuchin14bcd6a68c4d
diff --git a/app/models/custom_value/date_strategy.rb b/app/models/custom_value/date_strategy.rb
index d355b0187db..9b301376c96 100644
--- a/app/models/custom_value/date_strategy.rb
+++ b/app/models/custom_value/date_strategy.rb
@@ -30,9 +30,11 @@ class CustomValue::DateStrategy < CustomValue::FormatStrategy
include Redmine::I18n
def typed_value
- if value.present?
- Date.iso8601(value)
- end
+ return if value.blank?
+
+ Date.iso8601(value)
+ rescue Date::Error
+ nil
end
def formatted_value
diff --git a/spec/models/custom_value/date_strategy_spec.rb b/spec/models/custom_value/date_strategy_spec.rb
index ae6d89b6bd2..8aaed69a426 100644
--- a/spec/models/custom_value/date_strategy_spec.rb
+++ b/spec/models/custom_value/date_strategy_spec.rb
@@ -46,6 +46,12 @@ RSpec.describe CustomValue::DateStrategy do
it { is_expected.to eql(Date.iso8601(value)) }
end
+ context "value is not a date" do
+ let(:value) { "hello, world!" }
+
+ it { is_expected.to be_nil }
+ end
+
context "value is blank" do
let(:value) { "" }