diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 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 header def 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) : name end def api_request? diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 55bac61afe5..5411dc51f39 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -243,7 +243,7 @@ class MembersController < ApplicationController def 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) else e diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d92478c48e4..120e56d5a2d 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -178,7 +178,7 @@ module RepositoriesHelper str.force_encoding('ASCII-8BIT') end return 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-ascii if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb index 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 order def append_desc(criterion) - if criterion =~ / (asc|desc)\z/i + if / (asc|desc)\z/i.match?(criterion) criterion else "#{criterion} DESC" diff --git a/app/models/repository.rb b/app/models/repository.rb index 3f0ef5bc711..27f3515ab49 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -204,7 +204,7 @@ class Repository < ApplicationRecord name = name.to_s return 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 + '%'])).first end def latest_changeset diff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rb index d81a50d7f9d..e6605834b5d 100644 --- a/app/services/custom_fields/create_service.rb +++ b/app/services/custom_fields/create_service.rb @@ -29,7 +29,7 @@ module CustomFields class CreateService < ::BaseServices::Create def self.careful_new_custom_field(type) - if type.to_s =~ /.+CustomField\z/ + if /.+CustomField\z/.match?(type.to_s) klass = type.to_s.constantize klass.new if klass.ancestors.include? CustomField end diff --git a/app/validators/secure_context_uri_validator.rb b/app/validators/secure_context_uri_validator.rb index 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::EachValidator def self.secure_context_uri?(uri) return true if uri.scheme == 'https' # https is always safe return 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.rb index ed584fb5388..22277e347d1 100644 --- a/app/workers/backup_job.rb +++ b/app/workers/backup_job.rb @@ -199,7 +199,7 @@ class BackupJob < ApplicationJob def 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}" end diff --git a/config/environments/production.rb b/config/environments/production.rb index 3d2f14c5629..f97a93c9b86 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -89,10 +89,10 @@ OpenProject::Application.configure do relative_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) false end diff --git a/config/initializers/log_slow_sql_queries.rb b/config/initializers/log_slow_sql_queries.rb index 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 do ActiveSupport::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 durations duration = ((finish - start) * 1000).round(4) diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb index 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' end end diff --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.rb index 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_extension ActiveRecord::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.rb index 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 : false end end diff --git a/lib/open_project/scm/adapters/local_client.rb b/lib/open_project/scm/adapters/local_client.rb index 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 OpenProject end def target(path = '') - base = path.match(/\A\//) ? root_url : url + base = path.match?(/\A\//) ? root_url : url "#{base}/#{path}" end diff --git a/lib/open_project/scm/adapters/subversion.rb b/lib/open_project/scm/adapters/subversion.rb index 065eace0bfe..d424d78f736 100644 --- a/lib/open_project/scm/adapters/subversion.rb +++ b/lib/open_project/scm/adapters/subversion.rb @@ -103,7 +103,7 @@ module OpenProject return 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') end end diff --git a/lib/open_project/text_formatting/filters/attachment_filter.rb b/lib/open_project/text_formatting/filters/attachment_filter.rb index 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::TextFormatting filename = 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 attachment if (attachment = attachments.detect { |att| att.filename.downcase == filename }) diff --git a/lib/redmine/diff_table.rb b/lib/redmine/diff_table.rb index 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 ends def add_line(line) if @parsing - if line =~ /^[^+\-\s@\\]/ + if /^[^+\-\s@\\]/.match?(line) @parsing = false return false elsif line =~ /^@@ (\+|-)(\d+)(,\d+)? (\+|-)(\d+)(,\d+)? @@/ @@ -117,7 +117,7 @@ module Redmine true else write_offsets - if line[0, 1] =~ /\s/ + if /\s/.match?(line[0, 1]) diff = Diff.new diff.line_right = line[1..-1] diff.nb_line_right = @line_num_r diff --git a/lib/tasks/git.rake b/lib/tasks/git.rake index 4d3a33dc695..6cbb365642f 100644 --- a/lib/tasks/git.rake +++ b/lib/tasks/git.rake @@ -82,7 +82,7 @@ namespace :git do puts 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.rb index 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 ::Avatars end end - 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)) end diff --git a/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rb b/modules/backlogs/lib/open_project/backlogs/hooks/layout_hook.rb index 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::Hooks end if 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.rb index 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.destroy flash[:notice] = t(:notice_successful_delete) - if request.referer =~ /cost_reports/ + if /cost_reports/.match?(request.referer) redirect_to controller: '/cost_reports', action: :index else redirect_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.rb index 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::CustomFieldMixin def remove_subclasses module_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) end end diff --git a/script/api/spec b/script/api/spec index 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" puts puts "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 : :json begin if format == :yaml diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb index 4706972af6b..e92e91178f7 100644 --- a/spec/support/pages/projects/index.rb +++ b/spec/support/pages/projects/index.rb @@ -124,7 +124,7 @@ module Pages elsif 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) end diff --git a/spec/support/shared/with_direct_uploads.rb b/spec/support/shared/with_direct_uploads.rb index 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 fields headers: { 'Access-Control-Allow-Methods' => 'POST', 'Access-Control-Allow-Origin' => '*'