]> source.dussan.org Git - redmine.git/commitdiff
Use Regexp#match? to reduce allocations of MatchData object (#28940).
authorGo MAEDA <maeda@farend.jp>
Wed, 27 Mar 2019 02:15:24 +0000 (02:15 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 27 Mar 2019 02:15:24 +0000 (02:15 +0000)
Patch by Pavel Rosický.

git-svn-id: http://svn.redmine.org/redmine/trunk@18011 e93f8b46-1217-0410-a6f0-8f06a7374b81

34 files changed:
app/controllers/application_controller.rb
app/controllers/repositories_controller.rb
app/controllers/sys_controller.rb
app/helpers/queries_helper.rb
app/models/attachment.rb
app/models/import.rb
app/models/issue.rb
app/models/mail_handler.rb
app/models/principal.rb
app/models/project.rb
app/models/query.rb
app/models/repository.rb
app/models/repository/mercurial.rb
app/models/token.rb
app/models/workflow_permission.rb
lib/plugins/open_id_authentication/lib/open_id_authentication.rb
lib/redmine/codeset_util.rb
lib/redmine/configuration.rb
lib/redmine/core_ext/active_record.rb
lib/redmine/database.rb
lib/redmine/export/pdf.rb
lib/redmine/field_format.rb
lib/redmine/nested_set/issue_nested_set.rb
lib/redmine/nested_set/project_nested_set.rb
lib/redmine/platform.rb
lib/redmine/scm/adapters/abstract_adapter.rb
lib/redmine/scm/adapters/cvs_adapter.rb
lib/redmine/scm/adapters/filesystem_adapter.rb
lib/redmine/scm/adapters/mercurial_adapter.rb
lib/redmine/scm/adapters/subversion_adapter.rb
lib/redmine/sort_criteria.rb
lib/redmine/unified_diff.rb
lib/redmine/wiki_formatting.rb
lib/redmine/wiki_formatting/macros.rb

index 446cecc359239da6ce3e772745a95e607d652046..bf660c50b9e2495ff23c6353a6b0fea8b3fdd7a8 100644 (file)
@@ -114,7 +114,7 @@ class ApplicationController < ActionController::Base
       if (key = api_key_from_request)
         # Use API key
         user = User.find_by_api_key(key)
-      elsif request.authorization.to_s =~ /\ABasic /i
+      elsif /\ABasic /i.match?(request.authorization.to_s)
         # HTTP Basic, either username/password or API key/random
         authenticate_with_http_basic do |username, password|
           user = User.try_to_login(username, password) || User.find_by_api_key(username)
@@ -441,11 +441,11 @@ class ApplicationController < ActionController::Base
     path = uri.to_s
     # Ensure that the remaining URL starts with a slash, followed by a
     # non-slash character or the end
-    if path !~ %r{\A/([^/]|\z)}
+    if !%r{\A/([^/]|\z)}.match?(path)
       return false
     end
 
-    if path.match(%r{/(login|account/register|account/lost_password)})
+    if %r{/(login|account/register|account/lost_password)}.match?(path)
       return false
     end
 
@@ -626,7 +626,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|Edge)} ? ERB::Util.url_encode(name) : name
+    %r{(MSIE|Trident|Edge)}.match?(request.env['HTTP_USER_AGENT']) ? ERB::Util.url_encode(name) : name
   end
 
   def api_request?
index ff950799bdee24e582ef04cec8810639fb51c93c..85b421e7754d596b472d4e9f37269d6fba61c2fb 100644 (file)
@@ -320,7 +320,7 @@ class RepositoriesController < ApplicationController
     @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
     @rev_to = params[:rev_to]
 
-    unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
+    unless REV_PARAM_RE.match?(@rev.to_s) && REV_PARAM_RE.match?(@rev_to.to_s)
       if @repository.branches.blank?
         raise InvalidRevisionParam
       end
index 5547871141c26230b96208227b588fe8fbe8c9af..4bcaa2df188d3a564c748d12a9393c3faaf30d8f 100644 (file)
@@ -52,7 +52,7 @@ class SysController < ActionController::Base
     scope = Project.active.has_module(:repository)
     if params[:id]
       project = nil
-      if params[:id].to_s =~ /^\d*$/
+      if /^\d*$/.match?(params[:id].to_s)
         project = scope.find(params[:id])
       else
         project = scope.find_by_identifier(params[:id])
index 24207b4c18fcb1af1f90ae159a2f169f9a7ef64b..bc9752cb66b422c3ac7ddc9754ee848862f5da40 100644 (file)
@@ -30,7 +30,7 @@ module QueriesHelper
         group = :label_relations
       elsif field_options[:type] == :tree
         group = query.is_a?(IssueQuery) ? :label_relations : nil
-      elsif field =~ /^cf_\d+\./
+      elsif /^cf_\d+\./.match?(field)
         group = (field_options[:through] || field_options[:field]).try(:name)
       elsif field =~ /^(.+)\./
         # association filters
index a4870e3805b2da5451eb5a5d0b09aa93d4ec7adb..45560d0dc19c3cc04f6558d410c8501e880c8e94 100644 (file)
@@ -245,7 +245,7 @@ class Attachment < ActiveRecord::Base
   end
 
   def is_diff?
-    self.filename =~ /\.(patch|diff)$/i
+    /\.(patch|diff)$/i.match?(filename)
   end
 
   def is_pdf?
@@ -494,7 +494,7 @@ class Attachment < ActiveRecord::Base
   def self.disk_filename(filename, directory=nil)
     timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
     ascii = ''
-    if filename =~ %r{^[a-zA-Z0-9_\.\-]*$} && filename.length <= 50
+    if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
       ascii = filename
     else
       ascii = Digest::MD5.hexdigest(filename)
index 28c76268d8275d896463596d98767eecc31822be..7009f2e7e9373e5d7268cc76ec912c49d439dbc9 100644 (file)
@@ -79,7 +79,7 @@ class Import < ActiveRecord::Base
   # Returns the full path of the file to import
   # It is stored in tmp/imports with a random hex as filename
   def filepath
-    if filename.present? && filename =~ /\A[0-9a-f]+\z/
+    if filename.present? && /\A[0-9a-f]+\z/.match?(filename)
       File.join(Rails.root, "tmp", "imports", filename)
     else
       nil
index cd13fd3c55a862418f401117a9e13ac6694ffc89..3bccbb3483ba59fa6cf9bf7b5c5d08b0bbdd5161 100644 (file)
@@ -528,7 +528,7 @@ class Issue < ActiveRecord::Base
 
     # Project and Tracker must be set before since new_statuses_allowed_to depends on it.
     if (p = attrs.delete('project_id')) && safe_attribute?('project_id')
-      if p.is_a?(String) && !p.match(/^\d*$/)
+      if p.is_a?(String) && !/^\d*$/.match?(p)
         p_id = Project.find_by_identifier(p).try(:id)
       else
         p_id = p.to_i
@@ -769,7 +769,7 @@ class Issue < ActiveRecord::Base
     user = new_record? ? author : current_journal.try(:user)
 
     required_attribute_names(user).each do |attribute|
-      if attribute =~ /^\d+$/
+      if /^\d+$/.match?(attribute)
         attribute = attribute.to_i
         v = custom_field_values.detect {|v| v.custom_field_id == attribute }
         if v && Array(v.value).detect(&:present?).nil?
index 52faef1354b8a6cd2a547091175b50e85f5feb41..534e2daef2e63c56e63a6d180b27383002ea0efd 100755 (executable)
@@ -103,7 +103,7 @@ class MailHandler < ActionMailer::Base
       value = email.header[key]
       if value
         value = value.to_s.downcase
-        if (ignored_value.is_a?(Regexp) && value.match(ignored_value)) || value == ignored_value
+        if (ignored_value.is_a?(Regexp) && ignored_value.match?(value)) || value == ignored_value
           if logger
             logger.info "MailHandler: ignoring email with #{key}:#{value} header"
           end
@@ -316,7 +316,7 @@ class MailHandler < ActionMailer::Base
       else
         regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i
       end
-      if attachment.filename.to_s =~ regexp
+      if regexp.match?(attachment.filename.to_s)
         logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}"
         return false
       end
index 6e77cd8666f77e1e78d99545c06cd7a2abfcb453..4ac3f2e9fe223ac9e43e98268a794ad4e0e69dd5 100644 (file)
@@ -176,7 +176,7 @@ class Principal < ActiveRecord::Base
     principal ||= principals.detect {|a| keyword.casecmp(a.login.to_s) == 0}
     principal ||= principals.detect {|a| keyword.casecmp(a.mail.to_s) == 0}
 
-    if principal.nil? && keyword.match(/ /)
+    if principal.nil? && / /.match?(keyword)
       firstname, lastname = *(keyword.split) # "First Last Throwaway"
       principal ||= principals.detect {|a|
                                  a.is_a?(User) &&
index 04766c8578facc764c4347c06d1e4822991239cd..41d63b2706dcb9c87fcf9956f9e5ab040c10dec6 100644 (file)
@@ -313,7 +313,7 @@ class Project < ActiveRecord::Base
   end
 
   def self.find(*args)
-    if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
+    if args.first && args.first.is_a?(String) && !/^\d*$/.match?(args.first)
       project = find_by_identifier(*args)
       raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
       project
@@ -353,7 +353,7 @@ class Project < ActiveRecord::Base
       nil
     else
       # id is used for projects with a numeric identifier (compatibility)
-      @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id.to_s : identifier)
+      @to_param ||= (%r{^\d*$}.match?(identifier.to_s) ? id.to_s : identifier)
     end
   end
 
index d4d8f0434896ccd79718762b45293c38a28ae3da..da76b974de133a9671bcbe0aca33637900a96775 100644 (file)
@@ -439,17 +439,17 @@ class Query < ActiveRecord::Base
       if values_for(field)
         case type_for(field)
         when :integer
-          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/\A[+-]?\d+(,[+-]?\d+)*\z/) }
+          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/\A[+-]?\d+(,[+-]?\d+)*\z/.match?(v) }
         when :float
-          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/\A[+-]?\d+(\.\d*)?\z/) }
+          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/\A[+-]?\d+(\.\d*)?\z/.match?(v) }
         when :date, :date_past
           case operator_for(field)
           when "=", ">=", "<=", "><"
             add_filter_error(field, :invalid) if values_for(field).detect {|v|
-              v.present? && (!v.match(/\A\d{4}-\d{2}-\d{2}(T\d{2}((:)?\d{2}){0,2}(Z|\d{2}:?\d{2})?)?\z/) || parse_date(v).nil?)
+              v.present? && (!/\A\d{4}-\d{2}-\d{2}(T\d{2}((:)?\d{2}){0,2}(Z|\d{2}:?\d{2})?)?\z/.match?(v) || parse_date(v).nil?)
             }
           when ">t-", "<t-", "t-", ">t+", "<t+", "t+", "><t+", "><t-"
-            add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
+            add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/^\d+$/.match?(v) }
           end
         end
       end
@@ -1053,7 +1053,7 @@ class Query < ActiveRecord::Base
       raise "Unknown #{queried_class.name} association #{assoc}" unless customized_class
     end
     where = sql_for_field(field, operator, value, db_table, db_field, true)
-    if operator =~ /[<>]/
+    if /[<>]/.match?(operator)
       where = "(#{where}) AND #{db_table}.#{db_field} <> ''"
     end
     "#{queried_table_name}.#{customized_key} #{not_in} IN (" +
@@ -1398,7 +1398,7 @@ class Query < ActiveRecord::Base
 
   # Returns a Date or Time from the given filter value
   def parse_date(arg)
-    if arg.to_s =~ /\A\d{4}-\d{2}-\d{2}T/
+    if /\A\d{4}-\d{2}-\d{2}T/.match?(arg.to_s)
       Time.parse(arg) rescue nil
     else
       Date.parse(arg) rescue nil
index f44c02f502bb90de06bca10d5e96f62fc5de85c7..4331ae21ded53e5d393110b5ba817513ff9dec49 100644 (file)
@@ -149,7 +149,7 @@ class Repository < ActiveRecord::Base
   end
 
   def self.find_by_identifier_param(param)
-    if param.to_s =~ /^\d+$/
+    if /^\d+$/.match?(param.to_s)
       find_by_id(param)
     else
       find_by_identifier(param)
@@ -248,7 +248,7 @@ class Repository < ActiveRecord::Base
   def find_changeset_by_name(name)
     return nil if name.blank?
     s = name.to_s
-    if s.match(/^\d*$/)
+    if /^\d*$/.match?(s)
       changesets.find_by(:revision => s)
     else
       changesets.where("revision LIKE ?", s + '%').first
@@ -469,7 +469,7 @@ class Repository < ActiveRecord::Base
     regexp = Redmine::Configuration["scm_#{scm_name.to_s.downcase}_path_regexp"]
     if changes[attribute] && regexp.present?
       regexp = regexp.to_s.strip.gsub('%project%') {Regexp.escape(project.try(:identifier).to_s)}
-      unless send(attribute).to_s.match(Regexp.new("\\A#{regexp}\\z"))
+      unless Regexp.new("\\A#{regexp}\\z").match?(send(attribute).to_s)
         errors.add(attribute, :invalid)
       end
     end
index a0560735fad710f6ba8b1ea417d3c8d6f0f396f7..2033a73179df4859caf3838719eadccc143a4f47 100644 (file)
@@ -98,7 +98,7 @@ class Repository::Mercurial < Repository
   def find_changeset_by_name(name)
     return nil if name.blank?
     s = name.to_s
-    if /[^\d]/ =~ s or s.size > 8
+    if /[^\d]/.match?(s) || s.size > 8
       cs = changesets.where(:scmid => s).first
     else
       cs = changesets.find_by(:revision => s)
index cf32c6aca71f66fac413c2b32999bbe43925c4cc..98ef6151a458cc74123b7d951a219e7b33053622 100644 (file)
@@ -112,7 +112,7 @@ class Token < ActiveRecord::Base
   def self.find_token(action, key, validity_days=nil)
     action = action.to_s
     key = key.to_s
-    return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
+    return nil unless action.present? && /\A[a-z0-9]+\z/i.match?(key)
 
     token = Token.find_by(:action => action, :value => key)
     if token && (token.action == action) && (token.value == key) && token.user
index bf507dcef1f1855d97fb6394b3efe7f0ddba1ac1..3a0873cdd3a3bdc771974f7f24a5f30d0275ec5e 100644 (file)
@@ -64,7 +64,7 @@ class WorkflowPermission < WorkflowRule
   protected
 
   def validate_field_name
-    unless Tracker::CORE_FIELDS_ALL.include?(field_name) || field_name.to_s.match(/^\d+$/)
+    unless Tracker::CORE_FIELDS_ALL.include?(field_name) || /^\d+$/.match?(field_name.to_s)
       errors.add :field_name, :invalid
     end
   end
index 538f0cfdb378f0309d775c1421fab589b3f6f94b..2496dff9465e7acc1a75da57a8668d408ca81efa 100644 (file)
@@ -87,7 +87,7 @@ module OpenIdAuthentication
     # dodge XRIs -- TODO: validate, don't just skip.
     unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
       # does it begin with http?  if not, add it.
-      identifier = +"http://#{identifier}" unless identifier =~ /^http/i
+      identifier = +"http://#{identifier}" unless /^http/i.match?(identifier)
 
       # strip any fragments
       identifier.gsub!(/\#(.*)$/, '')
index d74d5de3918f09e8113987312607d3a8aedf9a88..657d057d6c0662804bd9b9b015f077a0b2f4e4bc 100644 (file)
@@ -42,7 +42,7 @@ module Redmine
       return if str.nil?
       str = str.b
       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
       str.force_encoding('UTF-8')
       encodings = Setting.repositories_encodings.split(',').collect(&:strip)
       encodings.each do |encoding|
index e8d01a2535a328f12b8c0694e3f31090f9cac3a2..4ecd4766b3e58c5eff33f058a2a60e019738cf51 100644 (file)
@@ -122,7 +122,7 @@ module Redmine
       # Checks the validness of regular expressions set for repository paths at startup
       def check_regular_expressions
         @config.each do |name, value|
-          if value.present? && name =~ /^scm_.+_path_regexp$/
+          if value.present? && /^scm_.+_path_regexp$/.match?(name)
             begin
               Regexp.new value.to_s.strip
             rescue => e
index d7f6cb9fcea30f9fd8e9de2d8c4b3c3578eb5f8f..fdff2d9d26c2414deddd16bf0d65bf503a9e3d0c 100644 (file)
@@ -21,7 +21,7 @@ class DateValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
     before_type_cast = record.attributes_before_type_cast[attribute.to_s]
     if before_type_cast.is_a?(String) && before_type_cast.present?
-      unless before_type_cast =~ /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/ && value
+      unless /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/.match?(before_type_cast) && value
         record.errors.add attribute, :not_a_date
       end
     end
index 225e0f3e89120a5c2960b605c131be9a8395f47e..9d0b70712aa369ef9cb92e96c874d48cea46da51 100644 (file)
@@ -23,7 +23,7 @@ module Redmine
     class << self
       # Returns true if the database is PostgreSQL
       def postgresql?
-        (ActiveRecord::Base.connection.adapter_name =~ /postgresql/i).present?
+        /postgresql/i.match?(ActiveRecord::Base.connection.adapter_name)
       end
 
       # Returns the PostgreSQL version or nil if another DBMS is used
@@ -48,7 +48,7 @@ module Redmine
 
       # Returns true if the database is MySQL
       def mysql?
-        (ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present?
+        /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
       end
 
       # Returns a SQL statement for case/accent (if possible) insensitive match
index 4ce7c7ac85cd884eac2592597cda02b48c8389e1..d76eed6688b53d74ac035d6d21de3fca012b6a01 100644 (file)
@@ -140,7 +140,7 @@ module Redmine
         def self.attach(attachments, filename, encoding)
           filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
           atta = nil
-          if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
+          if /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i.match?(filename_utf8)
             atta = Attachment.latest_attach(attachments, filename_utf8)
           end
           if atta && atta.readable? && atta.visible?
index e1aba49f5e8f2c5bb3c54a10f946aa33b15402dd..3d8a976fcbaed623f36cd28d745361e1c8bacd50 100644 (file)
@@ -251,7 +251,7 @@ module Redmine
             [text, url]
           end
           links = texts_and_urls.sort_by(&:first).map do |text, url|
-            css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+            css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
             view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
           end
           links.join(', ').html_safe
@@ -360,7 +360,7 @@ module Redmine
       def validate_single_value(custom_field, value, customized=nil)
         errs = super
         value = value.to_s
-        unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
+        unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value)
           errs << ::I18n.t('activerecord.errors.messages.invalid')
         end
         if custom_field.min_length && value.length < custom_field.min_length
@@ -442,12 +442,12 @@ module Redmine
             url = url_from_pattern(custom_field, value, customized)
           else
             url = value.to_s
-            unless url =~ %r{\A[a-z]+://}i
+            unless %r{\A[a-z]+://}i.match?(url)
               # no protocol found, use http by default
               url = "http://" + url
             end
           end
-          css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+          css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
           view.link_to value.to_s.truncate(40), url, :class => css_class
         else
           value.to_s
@@ -492,7 +492,7 @@ module Redmine
 
       def validate_single_value(custom_field, value, customized=nil)
         errs = super
-        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s.strip =~ /^[+-]?\d+$/
+        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
         errs
       end
 
@@ -536,7 +536,7 @@ module Redmine
       end
 
       def validate_single_value(custom_field, value, customized=nil)
-        if value =~ /^\d{4}-\d{2}-\d{2}$/ && (value.to_date rescue false)
+        if /^\d{4}-\d{2}-\d{2}$/.match?(value) && (value.to_date rescue false)
           []
         else
           [::I18n.t('activerecord.errors.messages.not_a_date')]
index 0280c7a2d8e66077feda3334549d3c58cbb74af0..985341e01fb1f4cea93e79b5914e8d47469ce218 100644 (file)
@@ -151,7 +151,7 @@ module Redmine
       end
 
       def lock_nested_set
-        if self.class.connection.adapter_name =~ /sqlserver/i
+        if /sqlserver/i.match?(self.class.connection.adapter_name)
           lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
           # Custom lock for SQLServer
           # This can be problematic if root_id or parent root_id changes
index bbf22e25801caaa56969833faa803a740fe5b67f..edd2fc765ba0938ae672c81e3588dab458357fc9 100644 (file)
@@ -121,7 +121,7 @@ module Redmine
 
       def lock_nested_set
         lock = true
-        if self.class.connection.adapter_name =~ /sqlserver/i
+        if /sqlserver/i.match?(self.class.connection.adapter_name)
           lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
         end
         self.class.order(:id).lock(lock).ids
index 8830803b7da44758c5f4cccb8fa445ee0731635b..490d9363b36015f9ff0daf7b2ae80457e3964c54 100644 (file)
@@ -21,8 +21,8 @@ module Redmine
   module Platform
     class << self
       def mswin?
-        (RUBY_PLATFORM =~ /(:?mswin|mingw)/) ||
-           (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
+        (/(:?mswin|mingw)/.match?(RUBY_PLATFORM)) ||
+           (RUBY_PLATFORM == 'java' && /windows/i.match?(ENV['OS'] || ENV['os']))
       end
     end
   end
index 55753d27ed89f33578708f6ea4b858afa006f9e5..d66f0da251a8c7c69fd8e68c5e8177bd9c13634f 100644 (file)
@@ -186,7 +186,7 @@ module Redmine
 
         def target(path, sq=true)
           path ||= ''
-          base = path.match(/^\//) ? root_url : url
+          base = /^\//.match?(path) ? root_url : url
           str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
           if sq
             str = shell_quote(str)
index baaa723abfcc490ec96a22746027d50540c79c9f..be9c3d4665fb1bc9852c6f1baa629151eb74e3af 100644 (file)
@@ -170,7 +170,7 @@ module Redmine
             file_state = nil
             branch_map = nil
             io.each_line() do |line|
-              if state != "revision" && /^#{ENDLOG}/ =~ line
+              if state != "revision" && /^#{ENDLOG}/.match?(line)
                 commit_log = ""
                 revision   = nil
                 state      = "entry_start"
@@ -183,9 +183,9 @@ module Redmine
                   logger.debug("Path #{entry_path} <=> Name #{entry_name}")
                 elsif /^head: (.+)$/ =~ line
                   entry_headRev = $1 #unless entry.nil?
-                elsif /^symbolic names:/ =~ line
+                elsif /^symbolic names:/.match?(line)
                   state = "symbolic" #unless entry.nil?
-                elsif /^#{STARTLOG}/ =~ line
+                elsif /^#{STARTLOG}/.match?(line)
                   commit_log = ""
                   state      = "revision"
                 end
index 4335244bedea86e1f21ec2380d407ae6848eec1f..0a6a32d7b85b4bde7c03ca6c7c2c925a2e2fd94e 100644 (file)
@@ -109,7 +109,7 @@ module Redmine
         # Here we do not shell-out, so we do not want quotes.
         def target(path=nil)
           # Prevent the use of ..
-          if path and !path.match(/(^|\/)\.\.(\/|$)/)
+          if path and !/(^|\/)\.\.(\/|$)/.match?(path)
             return "#{self.url}#{without_leading_slash(path)}"
           end
           return self.url
index b03da11c1de8dcd528499d2fff34ecf232ea91c0..d5a87f2b38aa2d3fd26e091a1c8f03d3ea864654 100644 (file)
@@ -297,10 +297,10 @@ module Redmine
         # Runs 'hg' command with the given args
         def hg(*args, &block)
           # as of hg 4.4.1, early parsing of bool options is not terminated at '--'
-          if args.any? { |s| s =~ HG_EARLY_BOOL_ARG }
+          if args.any? { |s| HG_EARLY_BOOL_ARG.match?(s) }
             raise HgCommandArgumentError, "malicious command argument detected"
           end
-          if args.take_while { |s| s != '--' }.any? { |s| s =~ HG_EARLY_LIST_ARG }
+          if args.take_while { |s| s != '--' }.any? { |s| HG_EARLY_LIST_ARG.match?(s) }
             raise HgCommandArgumentError, "malicious command argument detected"
           end
 
index 7e77e3fb9782173dfcf6bad72e7d201aeb5f3023..5ee7159c058b5286d28b8daba474f2ce86d195d6 100644 (file)
@@ -267,7 +267,7 @@ module Redmine
         end
 
         def target(path = '')
-          base = path.match(/^\//) ? root_url : url
+          base = /^\//.match?(path) ? root_url : url
           uri = "#{base}/#{path}"
           uri = URI.escape(URI.escape(uri), '[]')
           shell_quote(uri.gsub(/[?<>\*]/, ''))
index 9b48fdcfbffb0de1417e236c688741c7c0bd8082..2e70ea4f254b8312f05ce37103c3f69227e2e012 100644 (file)
@@ -96,7 +96,7 @@ module Redmine
 
     # Appends ASC/DESC to the sort criterion unless it has a fixed order
     def append_order(criterion, order)
-      if criterion =~ / (asc|desc)$/i
+      if / (asc|desc)$/i.match?(criterion)
         criterion
       else
         Arel.sql "#{criterion} #{order.to_s.upcase}"
index 7fa818751403fafa96ef625cf6f7630caa0aaf6b..0f83d92ec11a831dd8be2307b3ca78750e0662e6 100644 (file)
@@ -78,7 +78,7 @@ module Redmine
           @parsing = true
         end
       else
-        if line =~ %r{^[^\+\-\s@\\]}
+        if %r{^[^\+\-\s@\\]}.match?(line)
           @parsing = false
           return false
         elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
@@ -114,9 +114,9 @@ module Redmine
     def file_name=(arg)
       both_git_diff = false
       if file_name.nil?
-        @git_diff = true if arg =~ %r{^(a/|/dev/null)}
+        @git_diff = true if %r{^(a/|/dev/null)}.match?(arg)
       else
-        both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)})
+        both_git_diff = (@git_diff && %r{^(b/|/dev/null)}.match?(arg))
       end
       if both_git_diff
         if file_name && arg == "/dev/null"
@@ -168,7 +168,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
index 5152cc75261c32bb5b05d23be5d6e991452fe1dc..14d0dc8b377a97ca31d86ef912bc51d10af65b5c 100644 (file)
@@ -135,7 +135,7 @@ module Redmine
       def auto_link!(text)
         text.gsub!(AUTO_LINK_RE) do
           all, leading, proto, url, post = $&, $1, $2, $3, $6
-          if leading =~ /<a\s/i || leading =~ /![<>=]?/
+          if /<a\s/i.match?(leading) || /![<>=]?/.match?(leading)
             # don't replace URLs that are already linked
             # and URLs prefixed with ! !> !< != (textile images)
             all
@@ -157,7 +157,7 @@ module Redmine
       def auto_mailto!(text)
         text.gsub!(/([\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
           mail = $1
-          if text.match(/<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/)
+          if /<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/.match?(text)
             mail
           else
             %(<a class="email" href="mailto:#{ERB::Util.html_escape mail}">#{ERB::Util.html_escape mail}</a>).html_safe
index 48c91b6e82f76ea1ff094983818a24619d0a94e0..93ad93f904050cec4236cb80e2a0f860265dcc8e 100644 (file)
@@ -143,7 +143,7 @@ module Redmine
         # If a block of text is given, the closing tag }} must be at the start of a new line.
         def macro(name, options={}, &block)
           options.assert_valid_keys(:desc, :parse_args)
-          unless name.to_s.match(/\A\w+\z/)
+          unless /\A\w+\z/.match?(name.to_s)
             raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
           end
           unless block_given?
@@ -240,7 +240,7 @@ module Redmine
         filename = args.first
         raise 'Filename required' unless filename.present?
         size = options[:size]
-        raise 'Invalid size parameter' unless size.nil? || size.match(/^\d+$/)
+        raise 'Invalid size parameter' unless size.nil? || /^\d+$/.match?(size)
         size = size.to_i
         size = 200 unless size > 0
         if obj && obj.respond_to?(:attachments) && attachment = Attachment.latest_attach(obj.attachments, filename)