Project

General

Profile

Patch #28940 » match.patch

Pavel Rosický, 2018-06-04 01:19

View differences:

app/controllers/application_controller.rb (working copy)
112 112
      if (key = api_key_from_request)
113 113
        # Use API key
114 114
        user = User.find_by_api_key(key)
115
      elsif request.authorization.to_s =~ /\ABasic /i
115
      elsif /\ABasic /i.match?(request.authorization.to_s)
116 116
        # HTTP Basic, either username/password or API key/random
117 117
        authenticate_with_http_basic do |username, password|
118 118
          user = User.try_to_login(username, password) || User.find_by_api_key(username)
......
438 438
    path = uri.to_s
439 439
    # Ensure that the remaining URL starts with a slash, followed by a
440 440
    # non-slash character or the end
441
    if path !~ %r{\A/([^/]|\z)}
441
    if !%r{\A/([^/]|\z)}.match?(path)
442 442
      return false
443 443
    end
444 444

  
445
    if path.match(%r{/(login|account/register|account/lost_password)})
445
    if %r{/(login|account/register|account/lost_password)}.match?(path)
446 446
      return false
447 447
    end
448 448

  
......
623 623

  
624 624
  # Returns a string that can be used as filename value in Content-Disposition header
625 625
  def filename_for_content_disposition(name)
626
    request.env['HTTP_USER_AGENT'] =~ %r{(MSIE|Trident|Edge)} ? ERB::Util.url_encode(name) : name
626
    %r{(MSIE|Trident|Edge)}.match?(request.env['HTTP_USER_AGENT']) ? ERB::Util.url_encode(name) : name
627 627
  end
628 628

  
629 629
  def api_request?
app/controllers/repositories_controller.rb (working copy)
311 311
    @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
312 312
    @rev_to = params[:rev_to]
313 313

  
314
    unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
314
    unless REV_PARAM_RE.match?(@rev.to_s) && REV_PARAM_RE.match?(@rev_to.to_s)
315 315
      if @repository.branches.blank?
316 316
        raise InvalidRevisionParam
317 317
      end
app/controllers/sys_controller.rb (working copy)
50 50
    scope = Project.active.has_module(:repository)
51 51
    if params[:id]
52 52
      project = nil
53
      if params[:id].to_s =~ /^\d*$/
53
      if /^\d*$/.match?(params[:id].to_s)
54 54
        project = scope.find(params[:id])
55 55
      else
56 56
        project = scope.find_by_identifier(params[:id])
app/helpers/queries_helper.rb (working copy)
30 30
        group = :label_relations
31 31
      elsif field_options[:type] == :tree
32 32
        group = query.is_a?(IssueQuery) ? :label_relations : nil
33
      elsif field =~ /^cf_\d+\./
33
      elsif /^cf_\d+\./.match?(field)
34 34
        group = (field_options[:through] || field_options[:field]).try(:name)
35 35
      elsif field =~ /^(.+)\./
36 36
        # association filters
app/models/attachment.rb (working copy)
243 243
  end
244 244

  
245 245
  def is_diff?
246
    self.filename =~ /\.(patch|diff)$/i
246
    /\.(patch|diff)$/i.match?(filename)
247 247
  end
248 248

  
249 249
  def is_pdf?
......
484 484
  def self.disk_filename(filename, directory=nil)
485 485
    timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
486 486
    ascii = ''
487
    if filename =~ %r{^[a-zA-Z0-9_\.\-]*$} && filename.length <= 50
487
    if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
488 488
      ascii = filename
489 489
    else
490 490
      ascii = Digest::MD5.hexdigest(filename)
app/models/import.rb (working copy)
77 77
  # Returns the full path of the file to import
78 78
  # It is stored in tmp/imports with a random hex as filename
79 79
  def filepath
80
    if filename.present? && filename =~ /\A[0-9a-f]+\z/
80
    if filename.present? && /\A[0-9a-f]+\z/.match?(filename)
81 81
      File.join(Rails.root, "tmp", "imports", filename)
82 82
    else
83 83
      nil
app/models/issue.rb (working copy)
521 521

  
522 522
    # Project and Tracker must be set before since new_statuses_allowed_to depends on it.
523 523
    if (p = attrs.delete('project_id')) && safe_attribute?('project_id')
524
      if p.is_a?(String) && !p.match(/^\d*$/)
524
      if p.is_a?(String) && !/^\d*$/.match?(p)
525 525
        p_id = Project.find_by_identifier(p).try(:id)
526 526
      else
527 527
        p_id = p.to_i
......
762 762
    user = new_record? ? author : current_journal.try(:user)
763 763

  
764 764
    required_attribute_names(user).each do |attribute|
765
      if attribute =~ /^\d+$/
765
      if /^\d+$/.match?(attribute)
766 766
        attribute = attribute.to_i
767 767
        v = custom_field_values.detect {|v| v.custom_field_id == attribute }
768 768
        if v && Array(v.value).detect(&:present?).nil?
app/models/mail_handler.rb (working copy)
102 102
      value = email.header[key]
103 103
      if value
104 104
        value = value.to_s.downcase
105
        if (ignored_value.is_a?(Regexp) && value.match(ignored_value)) || value == ignored_value
105
        if (ignored_value.is_a?(Regexp) && ignored_value.match?(value)) || value == ignored_value
106 106
          if logger
107 107
            logger.info "MailHandler: ignoring email with #{key}:#{value} header"
108 108
          end
......
315 315
      else
316 316
        regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i
317 317
      end
318
      if attachment.filename.to_s =~ regexp
318
      if regexp.match?(attachment.filename.to_s)
319 319
        logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}"
320 320
        return false
321 321
      end
app/models/principal.rb (working copy)
172 172
    principal ||= principals.detect {|a| keyword.casecmp(a.login.to_s) == 0}
173 173
    principal ||= principals.detect {|a| keyword.casecmp(a.mail.to_s) == 0}
174 174

  
175
    if principal.nil? && keyword.match(/ /)
175
    if principal.nil? && / /.match?(keyword)
176 176
      firstname, lastname = *(keyword.split) # "First Last Throwaway"
177 177
      principal ||= principals.detect {|a|
178 178
                                 a.is_a?(User) &&
app/models/project.rb (working copy)
311 311
  end
312 312

  
313 313
  def self.find(*args)
314
    if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
314
    if args.first && args.first.is_a?(String) && !/^\d*$/.match?(args.first)
315 315
      project = find_by_identifier(*args)
316 316
      raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
317 317
      project
......
351 351
      nil
352 352
    else
353 353
      # id is used for projects with a numeric identifier (compatibility)
354
      @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id.to_s : identifier)
354
      @to_param ||= (%r{^\d*$}.match?(identifier.to_s) ? id.to_s : identifier)
355 355
    end
356 356
  end
357 357

  
app/models/query.rb (working copy)
414 414
      if values_for(field)
415 415
        case type_for(field)
416 416
        when :integer
417
          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/\A[+-]?\d+(,[+-]?\d+)*\z/) }
417
          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/\A[+-]?\d+(,[+-]?\d+)*\z/.match?(v) }
418 418
        when :float
419
          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/\A[+-]?\d+(\.\d*)?\z/) }
419
          add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/\A[+-]?\d+(\.\d*)?\z/.match?(v) }
420 420
        when :date, :date_past
421 421
          case operator_for(field)
422 422
          when "=", ">=", "<=", "><"
423 423
            add_filter_error(field, :invalid) if values_for(field).detect {|v|
424
              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?)
424
              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?)
425 425
            }
426 426
          when ">t-", "<t-", "t-", ">t+", "<t+", "t+", "><t+", "><t-"
427
            add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
427
            add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !/^\d+$/.match?(v) }
428 428
          end
429 429
        end
430 430
      end
......
1013 1013
      raise "Unknown #{queried_class.name} association #{assoc}" unless customized_class
1014 1014
    end
1015 1015
    where = sql_for_field(field, operator, value, db_table, db_field, true)
1016
    if operator =~ /[<>]/
1016
    if /[<>]/.match?(operator)
1017 1017
      where = "(#{where}) AND #{db_table}.#{db_field} <> ''"
1018 1018
    end
1019 1019
    "#{queried_table_name}.#{customized_key} #{not_in} IN (" +
......
1345 1345

  
1346 1346
  # Returns a Date or Time from the given filter value
1347 1347
  def parse_date(arg)
1348
    if arg.to_s =~ /\A\d{4}-\d{2}-\d{2}T/
1348
    if /\A\d{4}-\d{2}-\d{2}T/.match?(arg.to_s)
1349 1349
      Time.parse(arg) rescue nil
1350 1350
    else
1351 1351
      Date.parse(arg) rescue nil
app/models/repository.rb (working copy)
149 149
  end
150 150

  
151 151
  def self.find_by_identifier_param(param)
152
    if param.to_s =~ /^\d+$/
152
    if /^\d+$/.match?(param.to_s)
153 153
      find_by_id(param)
154 154
    else
155 155
      find_by_identifier(param)
......
248 248
  def find_changeset_by_name(name)
249 249
    return nil if name.blank?
250 250
    s = name.to_s
251
    if s.match(/^\d*$/)
251
    if /^\d*$/.match?(s)
252 252
      changesets.where("revision = ?", s).first
253 253
    else
254 254
      changesets.where("revision LIKE ?", s + '%').first
......
469 469
    regexp = Redmine::Configuration["scm_#{scm_name.to_s.downcase}_path_regexp"]
470 470
    if changes[attribute] && regexp.present?
471 471
      regexp = regexp.to_s.strip.gsub('%project%') {Regexp.escape(project.try(:identifier).to_s)}
472
      unless send(attribute).to_s.match(Regexp.new("\\A#{regexp}\\z"))
472
      unless Regexp.new("\\A#{regexp}\\z").match?(send(attribute).to_s)
473 473
        errors.add(attribute, :invalid)
474 474
      end
475 475
    end
app/models/repository/mercurial.rb (working copy)
96 96
  def find_changeset_by_name(name)
97 97
    return nil if name.blank?
98 98
    s = name.to_s
99
    if /[^\d]/ =~ s or s.size > 8
99
    if /[^\d]/.match?(s) || s.size > 8
100 100
      cs = changesets.where(:scmid => s).first
101 101
    else
102 102
      cs = changesets.where(:revision => s).first
app/models/token.rb (working copy)
110 110
  def self.find_token(action, key, validity_days=nil)
111 111
    action = action.to_s
112 112
    key = key.to_s
113
    return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
113
    return nil unless action.present? && /\A[a-z0-9]+\z/i.match?(key)
114 114

  
115 115
    token = Token.where(:action => action, :value => key).first
116 116
    if token && (token.action == action) && (token.value == key) && token.user
app/models/workflow_permission.rb (working copy)
62 62
  protected
63 63

  
64 64
  def validate_field_name
65
    unless Tracker::CORE_FIELDS_ALL.include?(field_name) || field_name.to_s.match(/^\d+$/)
65
    unless Tracker::CORE_FIELDS_ALL.include?(field_name) || /^\d+$/.match?(field_name.to_s)
66 66
      errors.add :field_name, :invalid
67 67
    end
68 68
  end
lib/plugins/open_id_authentication/lib/open_id_authentication.rb (working copy)
87 87
    # dodge XRIs -- TODO: validate, don't just skip.
88 88
    unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
89 89
      # does it begin with http?  if not, add it.
90
      identifier = "http://#{identifier}" unless identifier =~ /^http/i
90
      identifier = "http://#{identifier}" unless /^http/i.match?(identifier)
91 91

  
92 92
      # strip any fragments
93 93
      identifier.gsub!(/\#(.*)$/, '')
lib/redmine/codeset_util.rb (working copy)
39 39
      return str if str.nil?
40 40
      str.force_encoding('ASCII-8BIT')
41 41
      return str if str.empty?
42
      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
42
      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match?(str) # for us-ascii
43 43
      str.force_encoding('UTF-8')
44 44
      encodings = Setting.repositories_encodings.split(',').collect(&:strip)
45 45
      encodings.each do |encoding|
lib/redmine/configuration.rb (working copy)
114 114
      # Checks the validness of regular expressions set for repository paths at startup
115 115
      def check_regular_expressions
116 116
        @config.each do |name, value|
117
          if value.present? && name =~ /^scm_.+_path_regexp$/
117
          if value.present? && /^scm_.+_path_regexp$/.match?(name)
118 118
            begin
119 119
              Regexp.new value.to_s.strip
120 120
            rescue => e
lib/redmine/core_ext/active_record.rb (working copy)
19 19
  def validate_each(record, attribute, value)
20 20
    before_type_cast = record.attributes_before_type_cast[attribute.to_s]
21 21
    if before_type_cast.is_a?(String) && before_type_cast.present?
22
      unless before_type_cast =~ /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/ && value
22
      unless /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/.match?(before_type_cast) && value
23 23
        record.errors.add attribute, :not_a_date
24 24
      end
25 25
    end
lib/redmine/export/pdf.rb (working copy)
141 141
        def self.attach(attachments, filename, encoding)
142 142
          filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
143 143
          atta = nil
144
          if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
144
          if /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i.match?(filename_utf8)
145 145
            atta = Attachment.latest_attach(attachments, filename_utf8)
146 146
          end
147 147
          if atta && atta.readable? && atta.visible?
lib/redmine/field_format.rb (working copy)
249 249
            [text, url]
250 250
          end
251 251
          links = texts_and_urls.sort_by(&:first).map do |text, url|
252
            css_class = (url =~ /^https?:\/\//) ? 'external' : nil
252
            css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
253 253
            view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
254 254
          end
255 255
          links.join(', ').html_safe
......
358 358
      def validate_single_value(custom_field, value, customized=nil)
359 359
        errs = super
360 360
        value = value.to_s
361
        unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
361
        unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value)
362 362
          errs << ::I18n.t('activerecord.errors.messages.invalid')
363 363
        end
364 364
        if custom_field.min_length && value.length < custom_field.min_length
......
440 440
            url = url_from_pattern(custom_field, value, customized)
441 441
          else
442 442
            url = value.to_s
443
            unless url =~ %r{\A[a-z]+://}i
443
            unless %r{\A[a-z]+://}i.match?(url)
444 444
              # no protocol found, use http by default
445 445
              url = "http://" + url
446 446
            end
447 447
          end
448
          css_class = (url =~ /^https?:\/\//) ? 'external' : nil
448
          css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
449 449
          view.link_to value.to_s.truncate(40), url, :class => css_class
450 450
        else
451 451
          value.to_s
......
490 490

  
491 491
      def validate_single_value(custom_field, value, customized=nil)
492 492
        errs = super
493
        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s =~ /^[+-]?\d+$/
493
        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s)
494 494
        errs
495 495
      end
496 496

  
......
534 534
      end
535 535

  
536 536
      def validate_single_value(custom_field, value, customized=nil)
537
        if value =~ /^\d{4}-\d{2}-\d{2}$/ && (value.to_date rescue false)
537
        if /^\d{4}-\d{2}-\d{2}$/.match?(value) && (value.to_date rescue false)
538 538
          []
539 539
        else
540 540
          [::I18n.t('activerecord.errors.messages.not_a_date')]
lib/redmine/platform.rb (working copy)
19 19
  module Platform
20 20
    class << self
21 21
      def mswin?
22
        (RUBY_PLATFORM =~ /(:?mswin|mingw)/) ||
23
           (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
22
        (/(:?mswin|mingw)/.match?(RUBY_PLATFORM)) ||
23
           (RUBY_PLATFORM == 'java' && /windows/i.match?(ENV['OS'] || ENV['os']))
24 24
      end
25 25
    end
26 26
  end
lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
183 183

  
184 184
        def target(path, sq=true)
185 185
          path ||= ''
186
          base = path.match(/^\//) ? root_url : url
186
          base = /^\//.match?(path) ? root_url : url
187 187
          str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
188 188
          if sq
189 189
            str = shell_quote(str)
lib/redmine/scm/adapters/cvs_adapter.rb (working copy)
168 168
            file_state = nil
169 169
            branch_map = nil
170 170
            io.each_line() do |line|
171
              if state != "revision" && /^#{ENDLOG}/ =~ line
171
              if state != "revision" && /^#{ENDLOG}/.match?(line)
172 172
                commit_log = String.new
173 173
                revision   = nil
174 174
                state      = "entry_start"
......
181 181
                  logger.debug("Path #{entry_path} <=> Name #{entry_name}")
182 182
                elsif /^head: (.+)$/ =~ line
183 183
                  entry_headRev = $1 #unless entry.nil?
184
                elsif /^symbolic names:/ =~ line
184
                elsif /^symbolic names:/.match?(line)
185 185
                  state = "symbolic" #unless entry.nil?
186
                elsif /^#{STARTLOG}/ =~ line
186
                elsif /^#{STARTLOG}/.match?(line)
187 187
                  commit_log = String.new
188 188
                  state      = "revision"
189 189
                end
lib/redmine/scm/adapters/filesystem_adapter.rb (working copy)
107 107
        # Here we do not shell-out, so we do not want quotes.
108 108
        def target(path=nil)
109 109
          # Prevent the use of ..
110
          if path and !path.match(/(^|\/)\.\.(\/|$)/)
110
          if path and !/(^|\/)\.\.(\/|$)/.match?(path)
111 111
            return "#{self.url}#{without_leading_slash(path)}"
112 112
          end
113 113
          return self.url
lib/redmine/scm/adapters/mercurial_adapter.rb (working copy)
296 296
        # Runs 'hg' command with the given args
297 297
        def hg(*args, &block)
298 298
          # as of hg 4.4.1, early parsing of bool options is not terminated at '--'
299
          if args.any? { |s| s =~ HG_EARLY_BOOL_ARG }
299
          if args.any? { |s| HG_EARLY_BOOL_ARG.match?(s) }
300 300
            raise HgCommandArgumentError, "malicious command argument detected"
301 301
          end
302
          if args.take_while { |s| s != '--' }.any? { |s| s =~ HG_EARLY_LIST_ARG }
302
          if args.take_while { |s| s != '--' }.any? { |s| HG_EARLY_LIST_ARG.match?(s) }
303 303
            raise HgCommandArgumentError, "malicious command argument detected"
304 304
          end
305 305

  
lib/redmine/scm/adapters/subversion_adapter.rb (working copy)
265 265
        end
266 266

  
267 267
        def target(path = '')
268
          base = path.match(/^\//) ? root_url : url
268
          base = /^\//.match?(path) ? root_url : url
269 269
          uri = "#{base}/#{path}"
270 270
          uri = URI.escape(URI.escape(uri), '[]')
271 271
          shell_quote(uri.gsub(/[?<>\*]/, ''))
lib/redmine/sort_criteria.rb (working copy)
94 94

  
95 95
    # Appends ASC/DESC to the sort criterion unless it has a fixed order
96 96
    def append_order(criterion, order)
97
      if criterion =~ / (asc|desc)$/i
97
      if / (asc|desc)$/i.match?(criterion)
98 98
        criterion
99 99
      else
100 100
        "#{criterion} #{order.to_s.upcase}"
lib/redmine/unified_diff.rb (working copy)
76 76
          @parsing = true
77 77
        end
78 78
      else
79
        if line =~ %r{^[^\+\-\s@\\]}
79
        if %r{^[^\+\-\s@\\]}.match?(line)
80 80
          @parsing = false
81 81
          return false
82 82
        elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
......
112 112
    def file_name=(arg)
113 113
      both_git_diff = false
114 114
      if file_name.nil?
115
        @git_diff = true if arg =~ %r{^(a/|/dev/null)}
115
        @git_diff = true if %r{^(a/|/dev/null)}.match?(arg)
116 116
      else
117
        both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)})
117
        both_git_diff = (@git_diff && %r{^(b/|/dev/null)}.match?(arg))
118 118
      end
119 119
      if both_git_diff
120 120
        if file_name && arg == "/dev/null"
......
166 166
        true
167 167
      else
168 168
        write_offsets
169
        if line[0, 1] =~ /\s/
169
        if /\s/.match?(line[0, 1])
170 170
          diff = Diff.new
171 171
          diff.line_right = line[1..-1]
172 172
          diff.nb_line_right = @line_num_r
lib/redmine/wiki_formatting.rb (working copy)
133 133
      def auto_link!(text)
134 134
        text.gsub!(AUTO_LINK_RE) do
135 135
          all, leading, proto, url, post = $&, $1, $2, $3, $6
136
          if leading =~ /<a\s/i || leading =~ /![<>=]?/
136
          if  /<a\s/i.match?(leading) || /![<>=]?/.match?(leading)
137 137
            # don't replace URLs that are already linked
138 138
            # and URLs prefixed with ! !> !< != (textile images)
139 139
            all
......
155 155
      def auto_mailto!(text)
156 156
        text.gsub!(/((?<!@)\b[\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
157 157
          mail = $1
158
          if text.match(/<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/)
158
          if /<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/.match?(text)
159 159
            mail
160 160
          else
161 161
            %(<a class="email" href="mailto:#{ERB::Util.html_escape mail}">#{ERB::Util.html_escape mail}</a>).html_safe
lib/redmine/wiki_formatting/macros.rb (working copy)
141 141
        # If a block of text is given, the closing tag }} must be at the start of a new line.
142 142
        def macro(name, options={}, &block)
143 143
          options.assert_valid_keys(:desc, :parse_args)
144
          unless name.to_s.match(/\A\w+\z/)
144
          unless /\A\w+\z/.match?(name.to_s)
145 145
            raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
146 146
          end
147 147
          unless block_given?
......
238 238
        filename = args.first
239 239
        raise 'Filename required' unless filename.present?
240 240
        size = options[:size]
241
        raise 'Invalid size parameter' unless size.nil? || size.match(/^\d+$/)
241
        raise 'Invalid size parameter' unless size.nil? || /^\d+$/.match?(size)
242 242
        size = size.to_i
243 243
        size = 200 unless size > 0
244 244
        if obj && obj.respond_to?(:attachments) && attachment = Attachment.latest_attach(obj.attachments, filename)
test/integration/sessions_test.rb (working copy)
37 37

  
38 38
    get '/my/account'
39 39
    assert_response 302
40
    assert flash[:error].match(/Your session has expired/)
40
    assert flash[:error].include?('Your session has expired')
41 41
  end
42 42

  
43 43
  def test_lock_user_kills_sessions
......
49 49

  
50 50
    get '/my/account'
51 51
    assert_response 302
52
    assert flash[:error].match(/Your session has expired/)
52
    assert flash[:error].include?('Your session has expired')
53 53
  end
54 54

  
55 55
  def test_update_user_does_not_kill_sessions
test/integration/welcome_test.rb (working copy)
26 26
    assert_response :success
27 27
    assert_equal 'text/plain', @response.content_type
28 28
    # Redmine::Utils.relative_url_root does not effect on Rails 5.1.4.
29
    assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
29
    assert %r{^Disallow: /projects/ecookbook/issues\r?$}.match?(@response.body)
30 30
  end
31 31
end
test/unit/lib/redmine/ciphering_test.rb (working copy)
23 23
    Redmine::Configuration.with 'database_cipher_key' => 'secret' do
24 24
      r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
25 25
      assert_equal 'foo', r.password
26
      assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
26
      assert /\Aaes-256-cbc:.+\Z/.match?(r.read_attribute(:password))
27 27
    end
28 28
  end
29 29

  
......
71 71
      r = Repository.order('id DESC').first
72 72
      # password can not be deciphered
73 73
      assert_nothing_raised do
74
        assert r.password.match(/\Aaes-256-cbc:.+\Z/)
74
        assert /\Aaes-256-cbc:.+\Z/.match?(r.password)
75 75
      end
76 76
    end
77 77
  end
......
87 87
      assert Repository.encrypt_all(:password)
88 88
      r = Repository.order('id DESC').first
89 89
      assert_equal 'bar', r.password
90
      assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
90
      assert /\Aaes-256-cbc:.+\Z/.match?(r.read_attribute(:password))
91 91
    end
92 92
  end
93 93

  
test/unit/lib/redmine/wiki_formatting/macros_test.rb (working copy)
175 175

  
176 176
  def test_macro_hello_world
177 177
    text = "{{hello_world}}"
178
    assert textilizable(text).match(/Hello world!/)
178
    assert textilizable(text).include?('Hello world!')
179 179
  end
180 180

  
181 181
  def test_macro_hello_world_should_escape_arguments
test/unit/mail_handler_test.rb (working copy)
62 62
    assert_equal 30, issue.done_ratio
63 63
    assert_equal Issue.find(4), issue.parent
64 64
    # keywords should be removed from the email body
65
    assert !issue.description.match(/^Project:/i)
66
    assert !issue.description.match(/^Status:/i)
67
    assert !issue.description.match(/^Start Date:/i)
65
    assert !/^Project:/i.match?(issue.description)
66
    assert !/^Status:/i.match?(issue.description)
67
    assert !/^Start Date:/i.match?(issue.description)
68 68
  end
69 69

  
70 70
  def test_add_issue_with_all_overrides
......
250 250
    assert_equal 'PostgreSQL', issue.custom_field_value(1)
251 251
    assert_equal 'Value for a custom field', issue.custom_field_value(2)
252 252
    assert_equal ['Mac OS X', 'Windows'], issue.custom_field_value(mutiple.id).sort
253
    assert !issue.description.match(/^searchable field:/i)
253
    assert !/^searchable field:/i.match?(issue.description)
254 254
  end
255 255

  
256 256
  def test_add_issue_with_version_custom_fields
......
849 849
    assert_equal User.find_by_login('jsmith'), issue.assigned_to
850 850
    assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
851 851
    # keywords should be removed from the email body
852
    assert !journal.notes.match(/^Status:/i)
853
    assert !journal.notes.match(/^Start Date:/i)
852
    assert !/^Status:/i.match?(journal.notes)
853
    assert !/^Start Date:/i.match?(journal.notes)
854 854
  end
855 855

  
856 856
  def test_update_issue_with_attachment
......
992 992
      assert_issue_created(issue)
993 993
      assert issue.description.include?('This paragraph is before delimiters')
994 994
      assert issue.description.include?('--- This line starts with a delimiter')
995
      assert !issue.description.match(/^---#{"\u00A0"}$/)
995
      assert !/^---#{"\u00A0"}$/.match?(issue.description)
996 996
      assert !issue.description.include?('This paragraph is after the delimiter')
997 997
    end
998 998
  end
......
1002 1002
      journal = submit_email('issue_update_with_quoted_reply_above.eml')
1003 1003
      assert journal.is_a?(Journal)
1004 1004
      assert journal.notes.include?('An update to the issue by the sender.')
1005
      assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
1005
      assert !Regexp.escape("--- Reply above. Do not remove this line. ---").match?(journal.notes)
1006 1006
      assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
1007 1007
    end
1008 1008
  end
......
1012 1012
      journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
1013 1013
      assert journal.is_a?(Journal)
1014 1014
      assert journal.notes.include?('An update to the issue by the sender.')
1015
      assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
1015
      assert !Regexp.escape("--- Reply above. Do not remove this line. ---").match?(journal.notes)
1016 1016
      assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
1017 1017
    end
1018 1018
  end
......
1024 1024
      assert issue.description.include?('This paragraph is before delimiters')
1025 1025
      assert !issue.description.include?('BREAK')
1026 1026
      assert !issue.description.include?('This paragraph is between delimiters')
1027
      assert !issue.description.match(/^---$/)
1027
      assert !/^---$/.match?(issue.description)
1028 1028
      assert !issue.description.include?('This paragraph is after the delimiter')
1029 1029
    end
1030 1030
  end
test/unit/principal_test.rb (working copy)
89 89
    results = Principal.like('jsmi')
90 90

  
91 91
    assert results.any?
92
    assert results.all? {|u| u.login.match(/jsmi/i) }
92
    assert results.all? {|u| /jsmi/i.match?(u.login) }
93 93
  end
94 94

  
95 95
  test "like scope should search firstname" do
96 96
    results = Principal.like('john')
97 97

  
98 98
    assert results.any?
99
    assert results.all? {|u| u.firstname.match(/john/i) }
99
    assert results.all? {|u| /john/i.match?(u.firstname) }
100 100
  end
101 101

  
102 102
  test "like scope should search lastname" do
103 103
    results = Principal.like('smi')
104 104

  
105 105
    assert results.any?
106
    assert results.all? {|u| u.lastname.match(/smi/i) }
106
    assert results.all? {|u| /smi/i.match?(u.lastname) }
107 107
  end
108 108

  
109 109
  test "like scope should search mail" do
110 110
    results = Principal.like('somenet')
111 111

  
112 112
    assert results.any?
113
    assert results.all? {|u| u.mail.match(/somenet/i) }
113
    assert results.all? {|u| /somenet/i.match?(u.mail) }
114 114
  end
115 115

  
116 116
  test "like scope should search firstname and lastname" do
(1-1/6)