diff --git a/Gemfile.lock b/Gemfile.lock index 88dcb7f10..fdb353fc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -448,8 +448,8 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.1.0) - rubocop (>= 0.67.0) + rubocop-performance (1.4.1) + rubocop (>= 0.71.0) rubocop-rails (2.3.2) rack (>= 1.1) rubocop (>= 0.72.0) diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index d7aa3df34..8b1981f20 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -303,7 +303,7 @@ curl http://localhost/api/v1/monitoring/amount_check?token=XXX&periode=1h raise Exceptions::UnprocessableEntity, 'periode is missing!' if params[:periode].blank? scale = params[:periode][-1, 1] - raise Exceptions::UnprocessableEntity, 'periode need to have s, m, h or d as last!' if scale !~ /^(s|m|h|d)$/ + raise Exceptions::UnprocessableEntity, 'periode need to have s, m, h or d as last!' if !scale.match?(/^(s|m|h|d)$/) periode = params[:periode][0, params[:periode].length - 1] raise Exceptions::UnprocessableEntity, 'periode need to be an integer!' if periode.to_i.zero? diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index 6f587ed4d..b310d76dd 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -182,7 +182,7 @@ example # check if verify message exists subject = message_meta['ENVELOPE'].subject next if !subject - next if subject !~ /#{verify_string}/ + next if !subject.match?(/#{verify_string}/) Rails.logger.info " - verify email #{verify_string} found" timeout(600) do diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index 227b0a0be..b808cf0f2 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -117,7 +117,7 @@ returns next if !mail # check if verify message exists - next if mail !~ /#{verify_string}/ + next if !mail.match?(/#{verify_string}/) Rails.logger.info " - verify email #{verify_string} found" m.delete diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 9852baf94..c516cf75e 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -734,7 +734,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again 'image/gif': %w[gif image], } map.each do |type, ext| - next if headers_store['Content-Type'] !~ /^#{Regexp.quote(type)}/i + next if !headers_store['Content-Type'].match?(/^#{Regexp.quote(type)}/i) filename = if headers_store['Content-Description'].present? "#{headers_store['Content-Description']}.#{ext[0]}".to_s.force_encoding('utf-8') diff --git a/app/models/channel/filter/follow_up_possible_check.rb b/app/models/channel/filter/follow_up_possible_check.rb index b64043585..e4f639c13 100644 --- a/app/models/channel/filter/follow_up_possible_check.rb +++ b/app/models/channel/filter/follow_up_possible_check.rb @@ -8,7 +8,7 @@ module Channel::Filter::FollowUpPossibleCheck ticket = Ticket.lookup(id: ticket_id) return true if !ticket - return true if ticket.state.state_type.name !~ /^(closed|merged|removed)/i + return true if !ticket.state.state_type.name.match?(/^(closed|merged|removed)/i) # in case of closed tickets, remove follow-up information case ticket.group.follow_up_possible diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index a890878f4..9ae0c5a3b 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -104,7 +104,7 @@ module Channel::Filter::IdentifySender items.each do |address_data| email_address = address_data.address next if email_address.blank? - next if email_address !~ /@/ + next if !email_address.match?(/@/) next if email_address.match?(/\s/) user_create( @@ -132,7 +132,7 @@ module Channel::Filter::IdentifySender display_name = $1 end next if address.blank? - next if address !~ /@/ + next if !address.match?(/@/) next if address.match?(/\s/) user_create( diff --git a/app/models/channel/filter/out_of_office_check.rb b/app/models/channel/filter/out_of_office_check.rb index bed49ef9e..9d1b41078 100644 --- a/app/models/channel/filter/out_of_office_check.rb +++ b/app/models/channel/filter/out_of_office_check.rb @@ -8,7 +8,7 @@ module Channel::Filter::OutOfOfficeCheck # check ms out of office characteristics if mail[ 'x-auto-response-suppress'.to_sym ] - return if mail[ 'x-auto-response-suppress'.to_sym ] !~ /all/i + return if !mail[ 'x-auto-response-suppress'.to_sym ].match?(/all/i) return if !mail[ 'x-ms-exchange-inbox-rules-loop'.to_sym ] mail[ 'x-zammad-out-of-office'.to_sym ] = true diff --git a/app/models/channel/filter/own_notification_loop_detection.rb b/app/models/channel/filter/own_notification_loop_detection.rb index 4c7629a93..8e4d12477 100644 --- a/app/models/channel/filter/own_notification_loop_detection.rb +++ b/app/models/channel/filter/own_notification_loop_detection.rb @@ -9,10 +9,10 @@ module Channel::Filter::OwnNotificationLoopDetection recedence = mail['precedence'.to_sym] return if !recedence - return if recedence !~ /bulk/i + return if !recedence.match?(/bulk/i) fqdn = Setting.get('fqdn') - return if message_id !~ /@#{Regexp.quote(fqdn)}>/i + return if !message_id.match?(/@#{Regexp.quote(fqdn)}>/i) mail[ 'x-zammad-ignore'.to_sym ] = true Rails.logger.info "Detected own sent notification mail and dropped it to prevent loops (message_id: #{message_id}, from: #{mail[:from]}, to: #{mail[:to]})" diff --git a/app/models/channel/filter/trusted.rb b/app/models/channel/filter/trusted.rb index 238d885d6..450358f33 100644 --- a/app/models/channel/filter/trusted.rb +++ b/app/models/channel/filter/trusted.rb @@ -8,7 +8,7 @@ module Channel::Filter::Trusted # check if trust x-headers if !channel[:trusted] mail.each_key do |key| - next if key !~ /^x-zammad/i + next if !key.match?(/^x-zammad/i) mail.delete(key) end @@ -17,7 +17,7 @@ module Channel::Filter::Trusted # verify values mail.each do |key, value| - next if key !~ /^x-zammad/i + next if !key.match?(/^x-zammad/i) # no assoc exists, remove header next if Channel::EmailParser.check_attributes_by_x_headers(key, value) diff --git a/app/models/concerns/has_search_sortable.rb b/app/models/concerns/has_search_sortable.rb index 188f621d3..75e239db1 100644 --- a/app/models/concerns/has_search_sortable.rb +++ b/app/models/concerns/has_search_sortable.rb @@ -75,7 +75,7 @@ returns # check order params[:order_by].each do |value| - raise "Found invalid order by value #{value}. Please use 'asc' or 'desc'." if value !~ /\A(asc|desc)\z/i + raise "Found invalid order by value #{value}. Please use 'asc' or 'desc'." if !value.match?(/\A(asc|desc)\z/i) order_by.push(value.downcase) end diff --git a/app/models/cti/driver/base.rb b/app/models/cti/driver/base.rb index 0e74c1448..9b602b060 100644 --- a/app/models/cti/driver/base.rb +++ b/app/models/cti/driver/base.rb @@ -94,7 +94,7 @@ class Cti::Driver::Base if routing_table.present? routing_table.each do |row| dest = row[:dest].gsub(/\*/, '.+?') - next if to !~ /^#{dest}$/ + next if !to.match?(/^#{dest}$/) return { action: 'set_caller_id', diff --git a/app/models/email_address.rb b/app/models/email_address.rb index b77b5cf1b..eaa1868a4 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -48,7 +48,7 @@ check and if channel not exists reset configured channels for email addresses return true if email.blank? self.email = email.downcase.strip - raise Exceptions::UnprocessableEntity, 'Invalid email' if email !~ /@/ + raise Exceptions::UnprocessableEntity, 'Invalid email' if !email.match?(/@/) raise Exceptions::UnprocessableEntity, 'Invalid email' if email.match?(/\s/) true diff --git a/app/models/observer/ticket/article/communicate_facebook.rb b/app/models/observer/ticket/article/communicate_facebook.rb index bbd3bc6cf..a791de0e1 100644 --- a/app/models/observer/ticket/article/communicate_facebook.rb +++ b/app/models/observer/ticket/article/communicate_facebook.rb @@ -23,7 +23,7 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer type = Ticket::Article::Type.lookup(id: record.type_id) return true if type.nil? - return true if type.name !~ /\Afacebook/ + return true if !type.name.start_with?('facebook') Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateFacebook::BackgroundJob.new(record.id)) end diff --git a/app/models/observer/ticket/article/communicate_facebook/background_job.rb b/app/models/observer/ticket/article/communicate_facebook/background_job.rb index 7517cfe4e..f77208d01 100644 --- a/app/models/observer/ticket/article/communicate_facebook/background_job.rb +++ b/app/models/observer/ticket/article/communicate_facebook/background_job.rb @@ -14,7 +14,7 @@ class Observer::Ticket::Article::CommunicateFacebook::BackgroundJob log_error(article, "Can't find ticket.preferences for Ticket.find(#{article.ticket_id})") if !ticket.preferences log_error(article, "Can't find ticket.preferences['channel_id'] for Ticket.find(#{article.ticket_id})") if !ticket.preferences['channel_id'] channel = Channel.lookup(id: ticket.preferences['channel_id']) - log_error(article, "Channel.find(#{channel.id}) isn't a twitter channel!") if channel.options[:adapter] !~ /\Afacebook/i + log_error(article, "Channel.find(#{channel.id}) isn't a twitter channel!") if !channel.options[:adapter].match?(/\Afacebook/i) # check source object id if !ticket.preferences['channel_fb_object_id'] diff --git a/app/models/observer/ticket/article/communicate_telegram.rb b/app/models/observer/ticket/article/communicate_telegram.rb index a492d35f1..efbcb4331 100644 --- a/app/models/observer/ticket/article/communicate_telegram.rb +++ b/app/models/observer/ticket/article/communicate_telegram.rb @@ -19,7 +19,7 @@ class Observer::Ticket::Article::CommunicateTelegram < ActiveRecord::Observer return true if !record.type_id type = Ticket::Article::Type.lookup(id: record.type_id) - return true if type.name !~ /\Atelegram/i + return true if !type.name.match?(/\Atelegram/i) Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateTelegram::BackgroundJob.new(record.id)) end diff --git a/app/models/observer/ticket/article/communicate_twitter.rb b/app/models/observer/ticket/article/communicate_twitter.rb index b804607fc..4def4a802 100644 --- a/app/models/observer/ticket/article/communicate_twitter.rb +++ b/app/models/observer/ticket/article/communicate_twitter.rb @@ -24,7 +24,7 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer type = Ticket::Article::Type.lookup(id: record.type_id) return true if type.nil? - return true if type.name !~ /\Atwitter/i + return true if !type.name.match?(/\Atwitter/i) raise Exceptions::UnprocessableEntity, 'twitter to: parameter is missing' if record.to.blank? && type['name'] == 'twitter direct-message' diff --git a/app/models/observer/ticket/article/communicate_twitter/background_job.rb b/app/models/observer/ticket/article/communicate_twitter/background_job.rb index ec2ba06ee..256bfd118 100644 --- a/app/models/observer/ticket/article/communicate_twitter/background_job.rb +++ b/app/models/observer/ticket/article/communicate_twitter/background_job.rb @@ -30,7 +30,7 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob end log_error(article, "No such channel id #{ticket.preferences['channel_id']}") if !channel - log_error(article, "Channel.find(#{channel.id}) isn't a twitter channel!") if channel.options[:adapter] !~ /\Atwitter/i + log_error(article, "Channel.find(#{channel.id}) isn't a twitter channel!") if !channel.options[:adapter].match?(/\Atwitter/i) begin tweet = channel.deliver( diff --git a/app/models/package.rb b/app/models/package.rb index 6a02394e7..2d146a7be 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -523,7 +523,7 @@ execute all pending package migrations at once end migrations_existing.each do |migration| - next if migration !~ /\.rb$/ + next if !migration.match?(/\.rb$/) version = nil name = nil diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 42cc680a9..00c1e76f2 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -568,7 +568,7 @@ condition example selector = selector_raw.stringify_keys raise "Invalid selector, operator missing #{selector.inspect}" if !selector['operator'] - raise "Invalid selector, operator #{selector['operator']} is invalid #{selector.inspect}" if selector['operator'] !~ /^(is|is\snot|contains|contains\s(not|all|one|all\snot|one\snot)|(after|before)\s\(absolute\)|(within\snext|within\slast|after|before)\s\(relative\))$/ + raise "Invalid selector, operator #{selector['operator']} is invalid #{selector.inspect}" if !selector['operator'].match?(/^(is|is\snot|contains|contains\s(not|all|one|all\snot|one\snot)|(after|before)\s\(absolute\)|(within\snext|within\slast|after|before)\s\(relative\))$/) # validate value / allow blank but only if pre_condition exists and is not specific if !selector.key?('value') || @@ -1358,7 +1358,7 @@ result # send notifications only to email addresses next if recipient_email.blank? - next if recipient_email !~ /@/ + next if !recipient_email.match?(/@/) # check if address is valid begin @@ -1375,7 +1375,7 @@ result recipient_email = "#{$2}@#{$3}" end next if recipient_email.blank? - next if recipient_email !~ /@/ + next if !recipient_email.match?(/@/) next if recipient_email.match?(/\s/) end diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 035940573..1e2ed02f5 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -69,7 +69,7 @@ returns def self.insert_urls(article) return article if article['attachments'].blank? - return article if article['content_type'] !~ %r{text/html}i + return article if !article['content_type'].match?(%r{text/html}i) return article if article['body'] !~ / locale.locale, diff --git a/app/models/user.rb b/app/models/user.rb index d8a550efa..3f7fb5f7a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -959,7 +959,7 @@ try to find correct name self.email = email.downcase.strip return true if id == 1 - raise Exceptions::UnprocessableEntity, 'Invalid email' if email !~ /@/ + raise Exceptions::UnprocessableEntity, 'Invalid email' if !email.match?(/@/) raise Exceptions::UnprocessableEntity, 'Invalid email' if email.match?(/\s/) true @@ -1182,7 +1182,7 @@ raise 'Minimum one user need to have admin permissions' def avatar_for_email_check return true if Setting.get('import_mode') return true if email.blank? - return true if email !~ /@/ + return true if !email.match?(/@/) return true if !saved_change_to_attribute?('email') && updated_at > Time.zone.now - 10.days # save/update avatar diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 032439e8c..98e692419 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -71,7 +71,7 @@ returns on fail provider_map.each_value do |settings| domains.each do |domain_to_check| - next if domain_to_check !~ /#{settings[:domain]}/i + next if !domain_to_check.match?(/#{settings[:domain]}/i) # add folder to config if needed if params[:folder].present? && settings[:inbound] && settings[:inbound][:options] @@ -339,7 +339,7 @@ returns on fail } white_map.each_key do |key| - next if e.message !~ /#{Regexp.escape(key)}/i + next if !e.message.match?(/#{Regexp.escape(key)}/i) return { result: 'ok', diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index 2e99f790c..727540feb 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -168,7 +168,7 @@ satinize html string based on whiltelist next if !node[attribute_name] href = cleanup_target(node[attribute_name]) - next if href !~ /(javascript|livescript|vbscript):/i + next if !href.match?(/(javascript|livescript|vbscript):/i) node.delete(attribute_name) end diff --git a/lib/idoit.rb b/lib/idoit.rb index fc5f3d1a7..1117176fc 100644 --- a/lib/idoit.rb +++ b/lib/idoit.rb @@ -141,7 +141,7 @@ or with filter: def self._url_cleanup(url) url.strip! - raise "Invalid endpoint '#{url}', need to start with http:// or https://" if url !~ %r{^http(s|)://}i + raise "Invalid endpoint '#{url}', need to start with http:// or https://" if !url.match?(%r{^http(s|)://}i) url = _url_cleanup_baseurl(url) url = "#{url}/src/jsonrpc.php" @@ -150,7 +150,7 @@ or with filter: def self._url_cleanup_baseurl(url) url.strip! - raise "Invalid endpoint '#{url}', need to start with http:// or https://" if url !~ %r{^http(s|)://}i + raise "Invalid endpoint '#{url}', need to start with http:// or https://" if !url.match?(%r{^http(s|)://}i) url.gsub!(%r{src/jsonrpc.php}, '') url.gsub(%r{([^:])//+}, '\\1/') diff --git a/lib/import/otrs/user.rb b/lib/import/otrs/user.rb index b2040c67f..75b0d3345 100644 --- a/lib/import/otrs/user.rb +++ b/lib/import/otrs/user.rb @@ -160,7 +160,7 @@ module Import result.push 'Admin' end - return result if group['Name'] !~ /^(stats|report)/ + return result if !group['Name'].match?(/^(stats|report)/) return result if !( permissions.include?('ro') || permissions.include?('rw') ) result.push 'Report' diff --git a/lib/notification_factory/mailer.rb b/lib/notification_factory/mailer.rb index 36777c315..928ab88d0 100644 --- a/lib/notification_factory/mailer.rb +++ b/lib/notification_factory/mailer.rb @@ -221,8 +221,8 @@ retunes result.each do |item| next if item['type'] != 'notification' next if item['object'] != 'Ticket' - next if item['value_to'] !~ /#{recipient.email}/i - next if item['value_to'] !~ /#{type}/i + next if !item['value_to'].match?(/#{recipient.email}/i) + next if !item['value_to'].match?(/#{type}/i) count += 1 end diff --git a/lib/sequencer/unit/import/exchange/attribute_examples.rb b/lib/sequencer/unit/import/exchange/attribute_examples.rb index 573fb7ddc..009ca0f81 100644 --- a/lib/sequencer/unit/import/exchange/attribute_examples.rb +++ b/lib/sequencer/unit/import/exchange/attribute_examples.rb @@ -20,7 +20,7 @@ class Sequencer break if extractor.enough end rescue NoMethodError => e - raise if e.message !~ /Viewpoint::EWS::/ + raise if !e.message.match?(/Viewpoint::EWS::/) logger.error e logger.error "Skipping folder_id '#{folder_id}' due to unsupported entries." diff --git a/lib/sessions.rb b/lib/sessions.rb index fcce72a9a..72ebd68f2 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -440,7 +440,7 @@ returns files.push entry end files.sort.each do |entry| - next if entry !~ /^send/ + next if !entry.match?(/^send/) message = Sessions.queue_file_read(path, entry) next if !message diff --git a/lib/stats/ticket_channel_distribution.rb b/lib/stats/ticket_channel_distribution.rb index 7fb264bf3..88919852f 100644 --- a/lib/stats/ticket_channel_distribution.rb +++ b/lib/stats/ticket_channel_distribution.rb @@ -86,7 +86,7 @@ class Stats::TicketChannelDistribution } type_ids = [] Ticket::Article::Type.all.each do |type| - next if type.name !~ /^#{channel[:sender]}/i + next if !type.name.match?(/^#{channel[:sender]}/i) type_ids.push type.id end diff --git a/lib/tasks/search_index_es.rake b/lib/tasks/search_index_es.rake index a1282b156..9ca640cf0 100644 --- a/lib/tasks/search_index_es.rake +++ b/lib/tasks/search_index_es.rake @@ -289,8 +289,8 @@ end def es_pipeline? number = es_version return false if number.blank? - return false if number =~ /^[2-4]\./ - return false if number =~ /^5\.[0-5]\./ + return false if number.match?(/^[2-4]\./) + return false if number.match?(/^5\.[0-5]\./) true end @@ -299,7 +299,7 @@ end def es_multi_index? number = es_version return false if number.blank? - return false if number =~ /^[2-5]\./ + return false if number.match?(/^[2-5]\./) true end @@ -308,7 +308,7 @@ end def es_type_in_mapping? number = es_version return true if number.blank? - return true if number =~ /^[2-6]\./ + return true if number.match?(/^[2-6]\./) false end diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb index d382d754c..b351bf818 100644 --- a/lib/twitter_sync.rb +++ b/lib/twitter_sync.rb @@ -698,7 +698,7 @@ process webhook messages from twitter channel.options[:sync][:search].each do |local_search| next if local_search[:term].blank? next if local_search[:group_id].blank? - next if item['text'] !~ /#{Regexp.quote(local_search[:term])}/i + next if !item['text'].match?(/#{Regexp.quote(local_search[:term])}/i) group_id = local_search[:group_id] break diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 33c56aea0..3e05e13e2 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1179,7 +1179,7 @@ set type of task (closeTab, closeNextInOverview, stayOnTab) cookies = instance.manage.all_cookies cookies.each do |cookie| # :name=>"_zammad_session_c25832f4de2", :value=>"adc31cd21615cb0a7ab269184ec8b76f", :path=>"/", :domain=>"localhost", :expires=>nil, :secure=>false} - next if cookie[:name] !~ /#{params[:name]}/i + next if !cookie[:name].match?(/#{params[:name]}/i) if params.key?(:value) && cookie[:value].to_s =~ /#{params[:value]}/i assert(true, "matching value '#{params[:value]}' in cookie '#{cookie}'") diff --git a/test/test_helper.rb b/test/test_helper.rb index c67e3b1f9..5cbf6b3c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -66,8 +66,8 @@ class ActiveSupport::TestCase count = 0 lines.reverse_each do |line| break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/) - next if line !~ /Send notification \(#{type}\)/ - next if line !~ /to:\s#{recipient}/ + next if !line.match?(/Send notification \(#{type}\)/) + next if !line.match?(/to:\s#{recipient}/) count += 1 end