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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.rbindex 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::FormatStrategyinclude Redmine::I18ndef typed_value- if value.present?- Date.iso8601(value)- end+ return if value.blank?++ Date.iso8601(value)+ rescue Date::Error+ nilenddef formatted_valuediff --git a/spec/models/custom_value/date_strategy_spec.rb b/spec/models/custom_value/date_strategy_spec.rbindex 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 doit { 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" dolet(:value) { "" }