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

ensure Queries::Projects::Selects::CustomField.key matches exactly

Ivan Kuchin1d96bacf8650
diff --git a/app/models/queries/projects/selects/custom_field.rb b/app/models/queries/projects/selects/custom_field.rb
index b1b19f29ee2..cf0585868b3 100644
--- a/app/models/queries/projects/selects/custom_field.rb
+++ b/app/models/queries/projects/selects/custom_field.rb
@@ -30,7 +30,7 @@ class Queries::Projects::Selects::CustomField < Queries::Selects::Base
validates :custom_field, presence: { message: I18n.t(:"activerecord.errors.messages.does_not_exist") }
def self.key
- /cf_(\d+)/
+ /\Acf_(\d+)\z/
end
def self.all_available
diff --git a/spec/models/queries/projects/selects/custom_field_spec.rb b/spec/models/queries/projects/selects/custom_field_spec.rb
new file mode 100644
index 00000000000..a3f39925aa2
--- /dev/null
+++ b/spec/models/queries/projects/selects/custom_field_spec.rb
@@ -0,0 +1,49 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+require "spec_helper"
+
+RSpec.describe Queries::Projects::Selects::CustomField do
+ describe ".key" do
+ it "matches key in correct format" do
+ expect(described_class.key).to match("cf_42")
+ end
+
+ it "doesn't match non numerical id" do
+ expect(described_class.key).not_to match("cf_cf")
+ end
+
+ it "doesn't match with prefix" do
+ expect(described_class.key).not_to match("xcf_42")
+ end
+
+ it "doesn't match with suffix" do
+ expect(described_class.key).not_to match("cf_42x")
+ end
+ end
+end