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
[#64348] Use a more explicit name for formula operators
Tobias Dillmannb6cd6e2bbdbd
diff --git a/app/forms/custom_fields/calculated_values/details_form.rb b/app/forms/custom_fields/calculated_values/details_form.rbindex e565ed10c7a..0394b5d805e 100644--- a/app/forms/custom_fields/calculated_values/details_form.rb+++ b/app/forms/custom_fields/calculated_values/details_form.rb@@ -82,7 +82,9 @@ module CustomFieldsdef formula_suggestions# Insert operators as plain text nodes instead of tokens, since displaying them as tokens would result# in too much visual clutter. We still want to offer autocompletion for them.- operators = CustomField::CalculatedValue::OPERATORS.map { |op| { key: op, label: op, insert_as_text: true } }+ operators = CustomField::CalculatedValue::MATH_OPERATORS_FOR_FORMULA.map do |op|+ { key: op, label: op, insert_as_text: true }+ endcustom_fields = model.usable_custom_field_references_for_formula.map do |cf|{ key: "cf_#{cf.id}", label: cf.name }diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rbindex 2355566a121..1a2b64dfe69 100644--- a/app/models/custom_field/calculated_value.rb+++ b/app/models/custom_field/calculated_value.rb@@ -34,7 +34,7 @@ module CustomField::CalculatedValueextend ActiveSupport::Concern# Mathematical operators that are allowed in the formula.- OPERATORS = %w[+ - * / % ( )].freeze+ MATH_OPERATORS_FOR_FORMULA = %w[+ - * / % ( )].freeze# Field formats that can be used within a formula.FIELD_FORMATS_FOR_FORMULA = %w[int float calculated_value].freeze@@ -126,7 +126,7 @@ module CustomField::CalculatedValue# Once this basic validation passes, the formula will be parsed and validated by Dentaku, which builds an AST# and ensures that the formula is really valid. A welcome side effect of the basic validation done here is that# it prevents built-in functions from being used in the formula, which we do not want to allow.- allowed_chars = OPERATORS + [" "]+ allowed_chars = MATH_OPERATORS_FOR_FORMULA + [" "]allowed_tokens = /\A(\{\{cf_\d+}}|\d+\.?\d*|\.\d+)\z/formula_string.split(Regexp.union(allowed_chars)).reject(&:empty?).all? do |token|