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
Fixes Performance/RegexpMatch offenses
Klaus Zanders26cee2729efa
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 62aea5d0d19..08b870b8d07 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -441,7 +441,7 @@ class ApplicationController < ActionController::Base# Returns a string that can be used as filename value in Content-Disposition headerdef filename_for_content_disposition(name)- request.env['HTTP_USER_AGENT'] =~ %r{(MSIE|Trident)} ? ERB::Util.url_encode(name) : name+ %r{(MSIE|Trident)}.match?(request.env['HTTP_USER_AGENT']) ? ERB::Util.url_encode(name) : nameenddef api_request?diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rbindex 55bac61afe5..5411dc51f39 100644--- a/app/controllers/members_controller.rb+++ b/app/controllers/members_controller.rb@@ -243,7 +243,7 @@ class MembersController < ApplicationControllerdef each_comma_separated(array, &block)array.map do |e|- if e.to_s.match /\d(,\d)*/+ if e.to_s.match? /\d(,\d)*/block.call(e)elseediff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rbindex d92478c48e4..120e56d5a2d 100644--- a/app/helpers/repositories_helper.rb+++ b/app/helpers/repositories_helper.rb@@ -178,7 +178,7 @@ module RepositoriesHelperstr.force_encoding('ASCII-8BIT')endreturn str if str.empty?- return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii+ return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match?(str) # for us-asciiif str.respond_to?(:force_encoding)str.force_encoding('UTF-8')diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rbindex 499a36d315c..d028a442da6 100644--- a/app/helpers/sort_helper.rb+++ b/app/helpers/sort_helper.rb@@ -187,7 +187,7 @@ module SortHelper# Appends DESC to the sort criterion unless it has a fixed orderdef append_desc(criterion)- if criterion =~ / (asc|desc)\z/i+ if / (asc|desc)\z/i.match?(criterion)criterionelse"#{criterion} DESC"diff --git a/app/models/repository.rb b/app/models/repository.rbindex 3f0ef5bc711..27f3515ab49 100644--- a/app/models/repository.rb+++ b/app/models/repository.rb@@ -204,7 +204,7 @@ class Repository < ApplicationRecordname = name.to_sreturn nil if name.blank?- changesets.where((name.match(/\A\d*\z/) ? ['revision = ?', name] : ['revision LIKE ?', name + '%'])).first+ changesets.where((name.match?(/\A\d*\z/) ? ['revision = ?', name] : ['revision LIKE ?', name + '%'])).firstenddef latest_changesetdiff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rbindex d81a50d7f9d..e6605834b5d 100644--- a/app/services/custom_fields/create_service.rb+++ b/app/services/custom_fields/create_service.rb@@ -29,7 +29,7 @@module CustomFieldsclass CreateService < ::BaseServices::Createdef self.careful_new_custom_field(type)- if type.to_s =~ /.+CustomField\z/+ if /.+CustomField\z/.match?(type.to_s)klass = type.to_s.constantizeklass.new if klass.ancestors.include? CustomFieldenddiff --git a/app/validators/secure_context_uri_validator.rb b/app/validators/secure_context_uri_validator.rbindex 4603443d0d0..72a1d665eb1 100644--- a/app/validators/secure_context_uri_validator.rb+++ b/app/validators/secure_context_uri_validator.rb@@ -53,7 +53,7 @@ class SecureContextUriValidator < ActiveModel::EachValidatordef self.secure_context_uri?(uri)return true if uri.scheme == 'https' # https is always safereturn true if uri.host == 'localhost' # Simple localhost- return true if uri.host =~ /\.localhost\.?$/ # i.e. 'foo.localhost' or 'foo.localhost.'+ return true if /\.localhost\.?$/.match?(uri.host) # i.e. 'foo.localhost' or 'foo.localhost.'# Check for loopback interface. The constructor can throw an exception for non IP addresses.# Those are invalid. And if the host is an IP address then we can check if it is loopback.diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rbindex ed584fb5388..22277e347d1 100644--- a/app/workers/backup_job.rb+++ b/app/workers/backup_job.rb@@ -199,7 +199,7 @@ class BackupJob < ApplicationJobdef get_cache_folder_path(attachment)# expecting paths like /tmp/op_uploaded_files/1639754082-3468-0002-0911/file.ext# just making extra sure so we don't delete anything wrong later on- unless attachment.diskfile.path =~ /#{attachment.file.cache_dir}\/[^\/]+\/[^\/]+/+ unless /#{attachment.file.cache_dir}\/[^\/]+\/[^\/]+/.match?(attachment.diskfile.path)raise "Unexpected cache path for attachment ##{attachment.id}: #{attachment.diskfile}"enddiff --git a/config/environments/production.rb b/config/environments/production.rbindex 3d2f14c5629..f97a93c9b86 100644--- a/config/environments/production.rb+++ b/config/environments/production.rb@@ -89,10 +89,10 @@ OpenProject::Application.configure dorelative_url = Regexp.escape(OpenProject::Configuration['rails_relative_url_root'])# When we match SYS controller API, allow non-https access- return true if request.path =~ /#{relative_url}\/sys\//+ return true if /#{relative_url}\/sys\//.match?(request.path)# When we match health checks- return true if request.path =~ /#{relative_url}\/health_checks/+ return true if /#{relative_url}\/health_checks/.match?(request.path)falseenddiff --git a/config/initializers/log_slow_sql_queries.rb b/config/initializers/log_slow_sql_queries.rbindex f592121daf4..9895ce0bc3e 100644--- a/config/initializers/log_slow_sql_queries.rb+++ b/config/initializers/log_slow_sql_queries.rb@@ -10,7 +10,7 @@ OpenProject::Application.configure doActiveSupport::Notifications.subscribe("sql.active_record") do |_name, start, finish, _id, data|# Skip transaction that may be blocked- next if data[:sql].match(/BEGIN|COMMIT/)+ next if data[:sql].match?(/BEGIN|COMMIT/)# Skip smaller durationsduration = ((finish - start) * 1000).round(4)diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rbindex 0e57ddd0e14..24e9992930e 100644--- a/config/initializers/zeitwerk.rb+++ b/config/initializers/zeitwerk.rb@@ -45,7 +45,7 @@ end# As it is complicated to return all the paths where such an initialization file might exist,# we simply return the general OpenProject namespace for such files.OpenProject::Inflector.rule do |_basename, abspath|- if abspath =~ /\/lib\/openproject-\w+.rb\z/+ if /\/lib\/openproject-\w+.rb\z/.match?(abspath)'OpenProject'endenddiff --git a/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb b/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rbindex 0685befb978..7b15c190587 100644--- a/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb+++ b/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb@@ -47,7 +47,7 @@ class AddGinTrgmIndexOnJournalsAndCustomValues < ActiveRecord::Migration[7.0]def safe_enable_pg_trgm_extensionActiveRecord::Base.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA pg_catalog;")rescue StandardError => e- raise unless e.message =~ /pg_trgm/+ raise unless /pg_trgm/.match?(e.message)# Rollback the transaction in order to recover from the error.ActiveRecord::Base.connection.execute 'ROLLBACK'diff --git a/lib/open_project/passwords.rb b/lib/open_project/passwords.rbindex 7bd04629b3d..6b725f6c313 100644--- a/lib/open_project/passwords.rb+++ b/lib/open_project/passwords.rb@@ -114,7 +114,7 @@ module OpenProject# Returns the number of active rules password adheres to.def self.size_active_rules_adhered_by(password)active_rules.count do |name|- password =~ RULES[name] ? true : false+ password&.match?(RULES[name]) ? true : falseendenddiff --git a/lib/open_project/scm/adapters/local_client.rb b/lib/open_project/scm/adapters/local_client.rbindex 8fe9173df88..1b1b8da0ada 100644--- a/lib/open_project/scm/adapters/local_client.rb+++ b/lib/open_project/scm/adapters/local_client.rb@@ -129,7 +129,7 @@ module OpenProjectenddef target(path = '')- base = path.match(/\A\//) ? root_url : url+ base = path.match?(/\A\//) ? root_url : url"#{base}/#{path}"enddiff --git a/lib/open_project/scm/adapters/subversion.rb b/lib/open_project/scm/adapters/subversion.rbindex 065eace0bfe..d424d78f736 100644--- a/lib/open_project/scm/adapters/subversion.rb+++ b/lib/open_project/scm/adapters/subversion.rb@@ -103,7 +103,7 @@ module OpenProjectreturn if doc.at_xpath('/info/entry/repository/uuid')stderr.each_line do |l|- Rails.logger.error("SVN access error: #{l}") if l =~ /E\d+:/+ Rails.logger.error("SVN access error: #{l}") if /E\d+:/.match?(l)raise Exceptions::SCMUnauthorized.new if l.include?('E215004: Authentication failed')endenddiff --git a/lib/open_project/text_formatting/filters/attachment_filter.rb b/lib/open_project/text_formatting/filters/attachment_filter.rbindex c851ea9e9d6..acfa264c458 100644--- a/lib/open_project/text_formatting/filters/attachment_filter.rb+++ b/lib/open_project/text_formatting/filters/attachment_filter.rb@@ -64,7 +64,7 @@ module OpenProject::TextFormattingfilename = node['src'].downcase# We only match a specific set of attributes as before- return unless filename =~ matched_filenames_regex+ return unless filename&.match?(matched_filenames_regex)# Try to find the attachmentif (attachment = attachments.detect { |att| att.filename.downcase == filename })diff --git a/lib/redmine/diff_table.rb b/lib/redmine/diff_table.rbindex 8dec6e94d09..c1a76626923 100644--- a/lib/redmine/diff_table.rb+++ b/lib/redmine/diff_table.rb@@ -44,7 +44,7 @@ module Redmine# Returns false when the diff endsdef add_line(line)if @parsing- if line =~ /^[^+\-\s@\\]/+ if /^[^+\-\s@\\]/.match?(line)@parsing = falsereturn falseelsif line =~ /^@@ (\+|-)(\d+)(,\d+)? (\+|-)(\d+)(,\d+)? @@/@@ -117,7 +117,7 @@ module Redminetrueelsewrite_offsets- if line[0, 1] =~ /\s/+ if /\s/.match?(line[0, 1])diff = Diff.newdiff.line_right = line[1..-1]diff.nb_line_right = @line_num_rdiff --git a/lib/tasks/git.rake b/lib/tasks/git.rakeindex 4d3a33dc695..6cbb365642f 100644--- a/lib/tasks/git.rake+++ b/lib/tasks/git.rake@@ -82,7 +82,7 @@ namespace :git doputs local_branches.join("\n")puts 'Proceed? (y/n)'- if STDIN.gets =~ /^y/i+ if /^y/i.match?(STDIN.gets)remote_branches.each do |b|match = b.match(/^([^\/]+)\/(.+)/)remote = match[1]diff --git a/modules/avatars/app/services/avatars/update_service.rb b/modules/avatars/app/services/avatars/update_service.rbindex c0b169f8378..549c777d0a6 100644--- a/modules/avatars/app/services/avatars/update_service.rb+++ b/modules/avatars/app/services/avatars/update_service.rb@@ -15,7 +15,7 @@ module ::Avatarsendend- unless avatar.original_filename =~ /\.(jpe?g|gif|png)\z/i+ unless /\.(jpe?g|gif|png)\z/i.match?(avatar.original_filename)return error_result(I18n.t(:wrong_file_format))enddiff --git a/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rb b/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rbindex 404c830ea51..b77567b56a7 100644--- a/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rb+++ b/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rb@@ -86,7 +86,7 @@ module OpenProject::Backlogs::Hooksendif params[:copy_tasks]- params[:copy_tasks] += ':' if params[:copy_tasks] !~ /:/+ params[:copy_tasks] += ':' if !/:/.match?(params[:copy_tasks])action, id = *params[:copy_tasks].split(/:/)story = (id.nil? ? nil : Story.find(Integer(id)))diff --git a/modules/costs/app/controllers/costlog_controller.rb b/modules/costs/app/controllers/costlog_controller.rbindex 2056d812ce1..b7c42c0a274 100644--- a/modules/costs/app/controllers/costlog_controller.rb+++ b/modules/costs/app/controllers/costlog_controller.rb@@ -86,7 +86,7 @@ class CostlogController < ApplicationController@cost_entry.destroyflash[:notice] = t(:notice_successful_delete)- if request.referer =~ /cost_reports/+ if /cost_reports/.match?(request.referer)redirect_to controller: '/cost_reports', action: :indexelseredirect_back fallback_location: work_package_path(@cost_entry.work_package)diff --git a/modules/reporting/app/models/cost_query/custom_field_mixin.rb b/modules/reporting/app/models/cost_query/custom_field_mixin.rbindex 867659ba843..2f59e7332e4 100644--- a/modules/reporting/app/models/cost_query/custom_field_mixin.rb+++ b/modules/reporting/app/models/cost_query/custom_field_mixin.rb@@ -68,7 +68,7 @@ module CostQuery::CustomFieldMixindef remove_subclassesmodule_parent.constants.each do |constant|- if constant.to_s.match /^CustomField\d+/+ if constant.to_s.match? /^CustomField\d+/module_parent.send(:remove_const, constant)endenddiff --git a/script/api/spec b/script/api/specindex e335b3ae0d2..a56167823ee 100755--- a/script/api/spec+++ b/script/api/spec@@ -1,6 +1,6 @@#!/usr/bin/env ruby-if ARGV.join(" ") =~ /((-h)|(--help))/+if /((-h)|(--help))/.match?(ARGV.join(" "))puts "Prints the self-contained OpenAPI 3.0 specification of OpenProject's APIv3"putsputs "usage: ./script/api/spec [--format JSON|yaml]"@@ -15,7 +15,7 @@ require_relative '../../lib/api/open_api'path = Pathname(__dir__).join("../../docs/api/apiv3/openapi-spec.yml")spec = API::OpenAPI.assemble_spec path-format = ARGV.join(" ") =~ /((--format)|(-f))((=)|(\s+))ya?ml/ ? :yaml : :json+format = /((--format)|(-f))((=)|(\s+))ya?ml/.match?(ARGV.join(" ")) ? :yaml : :jsonbeginif format == :yamldiff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rbindex 4706972af6b..e92e91178f7 100644--- a/spec/support/pages/projects/index.rb+++ b/spec/support/pages/projects/index.rb@@ -124,7 +124,7 @@ module Pageselsif name == 'created_at'select(human_operator, from: 'operator')set_created_at_filter(human_operator, values)- elsif name =~ /cf_\d+/+ elsif /cf_\d+/.match?(name)select(human_operator, from: 'operator')set_custom_field_filter(selected_filter, human_operator, values)enddiff --git a/spec/support/shared/with_direct_uploads.rb b/spec/support/shared/with_direct_uploads.rbindex 116b342bd01..333aa72455f 100644--- a/spec/support/shared/with_direct_uploads.rb+++ b/spec/support/shared/with_direct_uploads.rb@@ -135,7 +135,7 @@ class WithDirectUploads.stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'post').and_return(Proc.new do |_params, _headers, body, _url, _method|{- code: body =~ /X-Amz-Signature/ ? 201 : 403, # check that the expected post to AWS was made with the form fields+ code: /X-Amz-Signature/.match?(body) ? 201 : 403, # check that the expected post to AWS was made with the form fieldsheaders: {'Access-Control-Allow-Methods' => 'POST','Access-Control-Allow-Origin' => '*'