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

Remove catastrophic exponential-time regex

Christophe Bliard4683fae2f433
diff --git a/modules/reporting/app/models/cost_query/sql_statement.rb b/modules/reporting/app/models/cost_query/sql_statement.rb
index b46e49b0c69..27a4ca1252a 100644
--- a/modules/reporting/app/models/cost_query/sql_statement.rb
+++ b/modules/reporting/app/models/cost_query/sql_statement.rb
@@ -88,7 +88,7 @@ class CostQuery::SqlStatement < Report::SqlStatement
query.select({
count: 1, id: [model, :id], display_costs: 1,
real_costs: switch("#{table}.overridden_costs IS NULL" => [model, :costs], else: [model, :overridden_costs]),
- week: iso_year_week(:spent_on, model),
+ week: iso_year_week(field_name_for([model, :spent_on])),
singleton_value: 1
})
# FIXME: build this subquery from a sql_statement
diff --git a/modules/reporting/lib/report/chainable.rb b/modules/reporting/lib/report/chainable.rb
index d1bc97e3940..9072a23fe3c 100644
--- a/modules/reporting/lib/report/chainable.rb
+++ b/modules/reporting/lib/report/chainable.rb
@@ -329,7 +329,7 @@ module Report
def with_table(fields)
fields.map do |f|
place_field_name = self.class.put_sql_table_names[f] || self.class.put_sql_table_names[f].nil?
- place_field_name ? (field_name_for f, self) : f
+ place_field_name ? field_name_for([self, f]) : f
end
end
diff --git a/modules/reporting/lib/report/query_utils.rb b/modules/reporting/lib/report/query_utils.rb
index f70b3d11d29..acca09f7ebf 100644
--- a/modules/reporting/lib/report/query_utils.rb
+++ b/modules/reporting/lib/report/query_utils.rb
@@ -123,20 +123,17 @@ module Report::QueryUtils
# field_name_for nil # => 'NULL'
# field_name_for 'foo' # => 'foo'
# field_name_for [Issue, 'project_id'] # => 'issues.project_id'
- # field_name_for [:issue, 'project_id'], :entry # => 'issues.project_id'
- # field_name_for 'project_id', :entry # => 'entries.project_id'
+ # field_name_for [:issue, 'project_id'] # => 'issues.project_id'
#
# @param [Array, Object] arg Object to generate field name for.
# @param [Object, optional] default_table Table name to use if no table name is given.
# @return [String] Field name.
- def field_name_for(arg, default_table = nil)
+ def field_name_for(arg)
return 'NULL' unless arg
- return field_name_for(arg.keys.first, default_table) if arg.is_a? Hash
- return arg if arg.is_a? String and arg =~ /\.| |\(.*\)/
- return (table_name_for(arg.first || default_table) + '.') << arg.last.to_s if arg.is_a? Array and arg.size == 2
- return arg.to_s unless default_table
+ return field_name_for(arg.keys.first) if arg.is_a? Hash
+ return "#{table_name_for(arg.first)}.#{arg.last}" if arg.is_a? Array and arg.size == 2
- field_name_for [default_table, arg]
+ arg.to_s
end
##
@@ -211,9 +208,7 @@ module Report::QueryUtils
"#{safe_value}::#{type}"
end
- def iso_year_week(field, default_table = nil)
- field_name = field_name_for(field, default_table)
-
+ def iso_year_week(field_name)
"(EXTRACT(isoyear from #{field_name})*100 + \n\t\t" \
"EXTRACT(week from #{field_name} - \n\t\t" \
"(EXTRACT(dow FROM #{field_name})::int+6)%7))"