Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fixes Performance/StringReplacement offenses

Klaus Zandersf64fde1c1512
diff --git a/app/contracts/user_preferences/base_contract.rb b/app/contracts/user_preferences/base_contract.rb
index 056d5a52c1a..c4df8b17a2b 100644
--- a/app/contracts/user_preferences/base_contract.rb
+++ b/app/contracts/user_preferences/base_contract.rb
@@ -81,7 +81,7 @@ module UserPreferences
if time_zones.length == 1
time_zones.first
else
- time_zones.detect { |tz| tz.tzinfo.name.include?(tz.name.gsub(' ', '_')) }
+ time_zones.detect { |tz| tz.tzinfo.name.include?(tz.name.tr(' ', '_')) }
end
end
end
diff --git a/app/models/colors/hex_color.rb b/app/models/colors/hex_color.rb
index 18004ab99bb..76fdfd2d509 100644
--- a/app/models/colors/hex_color.rb
+++ b/app/models/colors/hex_color.rb
@@ -53,7 +53,7 @@ module Colors
# Splits the hexcode into rbg color array
def rgb_colors
hexcode
- .gsub('#', '') # Remove trailing #
+ .delete('#') # Remove trailing #
.scan(/../) # Pair hex chars
.map(&:hex) # to int
end
diff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rb
index a5d8baf7c67..ec8f75f0955 100644
--- a/app/models/work_package/pdf_export/common.rb
+++ b/app/models/work_package/pdf_export/common.rb
@@ -299,7 +299,7 @@ module WorkPackage::PDFExport::Common
def build_pdf_filename(base)
suffix = "_#{title_datetime}.pdf"
- "#{truncate(base, length: 255 - suffix.length)}#{suffix}".gsub(' ', '-')
+ "#{truncate(base, length: 255 - suffix.length)}#{suffix}".tr(' ', '-')
end
def title_datetime
diff --git a/lib/open_project/mime_type.rb b/lib/open_project/mime_type.rb
index 51f517bf710..69548105434 100644
--- a/lib/open_project/mime_type.rb
+++ b/lib/open_project/mime_type.rb
@@ -116,7 +116,7 @@ module OpenProject
# the mime type of name
def self.css_class_of(name)
mime = of(name)
- mime && mime.gsub('/', '-')
+ mime && mime.tr('/', '-')
end
def self.main_mimetype_of(name)
diff --git a/lib/open_project/patches/string.rb b/lib/open_project/patches/string.rb
index b88268bbe62..854d558e55a 100644
--- a/lib/open_project/patches/string.rb
+++ b/lib/open_project/patches/string.rb
@@ -42,7 +42,7 @@ module OpenProject
s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| $1 || $4 ? ($2.to_i + ($5.to_i / 60.0)) : m[0] }
end
# 2,5 => 2.5
- s.gsub!(',', '.')
+ s.tr!(',', '.')
begin; Kernel.Float(s); rescue StandardError; nil; end
end
diff --git a/lib/open_project/text_formatting/filters/setting_macros_filter.rb b/lib/open_project/text_formatting/filters/setting_macros_filter.rb
index 295dbd1513a..16bd12afb4a 100644
--- a/lib/open_project/text_formatting/filters/setting_macros_filter.rb
+++ b/lib/open_project/text_formatting/filters/setting_macros_filter.rb
@@ -49,7 +49,7 @@ module OpenProject::TextFormatting
html.gsub(self.class.regexp) do |matched_string|
variable = ($1.presence || $2.presence).dup
- variable.gsub!('\\', '')
+ variable.delete!('\\')
if ALLOWED_SETTINGS.include?(variable)
send variable
diff --git a/modules/calendar/spec/services/create_ical_service_spec.rb b/modules/calendar/spec/services/create_ical_service_spec.rb
index 0fdc154f1c9..5be86c56564 100644
--- a/modules/calendar/spec/services/create_ical_service_spec.rb
+++ b/modules/calendar/spec/services/create_ical_service_spec.rb
@@ -64,7 +64,7 @@ RSpec.describe Calendar::CreateICalService, type: :model do
let(:frozen_date_time) { DateTime.now }
let(:formatted_result) do
- subject.result.gsub("\r\n ", "").gsub("\r", "").gsub("\\n", "\n")
+ subject.result.gsub("\r\n ", "").delete("\r").gsub("\\n", "\n")
end
before do
@@ -84,7 +84,7 @@ RSpec.describe Calendar::CreateICalService, type: :model do
# rubocop:disable RSpec/ExampleLength
it 'converts work_packages to an ical string which contains all required ical fields in the correct format and order' do
- expected_ical_string = <<~EOICAL.gsub("\r ", "").gsub("\r", "")
+ expected_ical_string = <<~EOICAL.gsub("\r ", "").delete("\r")
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//OpenProject GmbH//OpenProject Core Project//EN
diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rb
index 1cf4d64aaea..e17a70f51f8 100644
--- a/modules/reporting/app/controllers/cost_reports_controller.rb
+++ b/modules/reporting/app/controllers/cost_reports_controller.rb
@@ -200,7 +200,7 @@ class CostReportsController < ApplicationController
f_cls = get_filter_class(name)
filter = f_cls.new.tap do |f|
- f.values = JSON.parse(params[:values].gsub("'", '"')) if params[:values].present? && params[:values]
+ f.values = JSON.parse(params[:values].tr("'", '"')) if params[:values].present? && params[:values]
end
render_widget Widget::Filters::Option, filter, to: canvas = ''
diff --git a/modules/reporting/lib/widget/group_bys.rb b/modules/reporting/lib/widget/group_bys.rb
index 362c50f935d..192fbe80f06 100644
--- a/modules/reporting/lib/widget/group_bys.rb
+++ b/modules/reporting/lib/widget/group_bys.rb
@@ -51,7 +51,7 @@ class Widget::GroupBys < Widget::Base
container = content_tag :div,
id: "group-by--#{type}",
class: 'group-by--container grid-block',
- 'data-initially-selected': initially_selected.to_json.gsub('"', "'") do
+ 'data-initially-selected': initially_selected.to_json.tr('"', "'") do
out = content_tag :span, class: 'group-by--caption grid-content shrink' do
content_tag :span do
I18n.t(:"label_#{type}")
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index 36cd29fc573..713e2ea3d3c 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -52,7 +52,7 @@ class Storages::ProjectStorage < ApplicationRecord
scope :automatic, -> { where(project_folder_mode: 'automatic') }
def project_folder_path
- "#{storage.group_folder}/#{project.name.gsub('/', '|')} (#{project.id})/"
+ "#{storage.group_folder}/#{project.name.tr('/', '|')} (#{project.id})/"
end
def project_folder_path_escaped
diff --git a/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb
index 1480d90be35..44d0acf3b1e 100644
--- a/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb
+++ b/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb
@@ -83,7 +83,7 @@ RSpec.describe OpenProject::TwoFactorAuthentication::TokenStrategy::Sns do
expect(api).to receive(:set_sms_attributes).and_return(nil)
expect(api)
.to receive(:publish)
- .with({ phone_number: phone.gsub(' ', ''),
+ .with({ phone_number: phone.delete(' '),
message: I18n.t('two_factor_authentication.text_otp_delivery_message_sms',
app_title: Setting.app_title, token: 1234) })
.and_return(api_result)
diff --git a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb
index 20519e1c32f..1247efb187a 100644
--- a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb
+++ b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb
@@ -142,7 +142,7 @@ module OpenProject::XlsExport
elsif c.instance_of?(BigDecimal)
c.to_f
else
- c.to_s.gsub("\r\n", "\n").gsub("\r", "\n")
+ c.to_s.gsub("\r\n", "\n").tr("\r", "\n")
end
column_array << value
@column_widths[i] = 0 if @column_widths[i].nil?
diff --git a/script/github_pr_errors b/script/github_pr_errors
index 48a8e545b1e..3574f725cf6 100755
--- a/script/github_pr_errors
+++ b/script/github_pr_errors
@@ -208,7 +208,7 @@ def get_jobs(workflow_run)
workflow_run['jobs_url']
cache_key = [
path_to_cache_key(workflow_run['jobs_url']),
- workflow_run['updated_at'].gsub(':', '')
+ workflow_run['updated_at'].delete(':')
].join('_')
cached(cache_key) { get_json(workflow_run['jobs_url']) }
end
diff --git a/spec/controllers/work_packages_controller_spec.rb b/spec/controllers/work_packages_controller_spec.rb
index 0c5675c1fc3..ab40f290e4c 100644
--- a/spec/controllers/work_packages_controller_spec.rb
+++ b/spec/controllers/work_packages_controller_spec.rb
@@ -291,7 +291,7 @@ RSpec.describe WorkPackagesController do
time = DateTime.new(2023, 6, 30, 23, 59)
allow(DateTime).to receive(:now).and_return(time)
expected_name = [stub_work_package.project.identifier, "##{stub_work_package.id}",
- stub_work_package.subject, '2023-06-30_23-59'].join('_').gsub(' ', '-')
+ stub_work_package.subject, '2023-06-30_23-59'].join('_').tr(' ', '-')
expected_type = 'application/pdf'
pdf_result = double('pdf_result',
error?: false,