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

[#64347] use Regexp.union

Tobias Dillmannebddccc2f75a
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rb
index af17cca718a..bf6826cf3ce 100644
--- a/app/models/custom_field/calculated_value.rb
+++ b/app/models/custom_field/calculated_value.rb
@@ -80,10 +80,9 @@ module CustomField::CalculatedValue
# 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 = %w[+ - / * ( )] + [" "]
- split_pattern = /\s|(\+)|(-)|(\/)|(\*)|(\()|(\))/
allowed_tokens = /^(cf_\d+|\d+\.?\d*|\.\d+|[#{allowed_chars.join}]+)$/
- formula_string.split(split_pattern).reject(&:empty?).all? do |token|
+ formula_string.split(Regexp.union(allowed_chars)).reject(&:empty?).all? do |token|
token.match?(allowed_tokens)
end
end