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

Use #subclasses instead of constantize for enumeration_class

Oliver Günther3b900829e74e
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index 9fe6c895edf..07841657eea 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -113,16 +113,8 @@ class EnumerationsController < ApplicationController
end
##
- # Find an enumeration class with the given Name
- # this should be fail save for nonsense names or names
- # which are no enumerations to prevent remote code execution attacks.
- # params: type (string)
+ # Find an enumeration class with the given name
def enumeration_class(type)
- klass = type.to_s.constantize
- raise NameError unless klass.ancestors.include? Enumeration
-
- klass
- rescue NameError
- nil
+ Enumeration.subclasses.detect { |cls| cls.name == type }
end
end