Fix Performance/DeletePrefix cop (#24796)

pull/59/head^2^2
Matt Jankowski 2023-05-02 15:07:45 -04:00 committed by GitHub
parent 05e3abe9d9
commit 668a19a2f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 9 additions and 24 deletions

View File

@ -303,21 +303,6 @@ Performance/CollectionLiteralInLoop:
- 'config/deploy.rb' - 'config/deploy.rb'
- 'lib/mastodon/media_cli.rb' - 'lib/mastodon/media_cli.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeMultiline.
Performance/DeletePrefix:
Exclude:
- 'app/controllers/authorize_interactions_controller.rb'
- 'app/controllers/concerns/signature_verification.rb'
- 'app/controllers/intents_controller.rb'
- 'app/lib/activitypub/case_transform.rb'
- 'app/lib/permalink_redirector.rb'
- 'app/lib/webfinger_resource.rb'
- 'app/services/activitypub/fetch_remote_actor_service.rb'
- 'app/services/backup_service.rb'
- 'app/services/resolve_account_service.rb'
- 'app/services/tag_search_service.rb'
# This cop supports unsafe autocorrection (--autocorrect-all). # This cop supports unsafe autocorrection (--autocorrect-all).
Performance/MapCompact: Performance/MapCompact:
Exclude: Exclude:

View File

@ -59,7 +59,7 @@ class AuthorizeInteractionsController < ApplicationController
end end
def uri_param def uri_param
params[:uri] || params.fetch(:acct, '').gsub(/\Aacct:/, '') params[:uri] || params.fetch(:acct, '').delete_prefix('acct:')
end end
def set_body_classes def set_body_classes

View File

@ -244,7 +244,7 @@ module SignatureVerification
end end
if key_id.start_with?('acct:') if key_id.start_with?('acct:')
stoplight_wrap_request { ResolveAccountService.new.call(key_id.gsub(/\Aacct:/, ''), suppress_errors: false) } stoplight_wrap_request { ResolveAccountService.new.call(key_id.delete_prefix('acct:'), suppress_errors: false) }
elsif !ActivityPub::TagManager.instance.local_uri?(key_id) elsif !ActivityPub::TagManager.instance.local_uri?(key_id)
account = ActivityPub::TagManager.instance.uri_to_actor(key_id) account = ActivityPub::TagManager.instance.uri_to_actor(key_id)
account ||= stoplight_wrap_request { ActivityPub::FetchRemoteKeyService.new.call(key_id, id: false, suppress_errors: false) } account ||= stoplight_wrap_request { ActivityPub::FetchRemoteKeyService.new.call(key_id, id: false, suppress_errors: false) }

View File

@ -9,7 +9,7 @@ class IntentsController < ApplicationController
if uri.scheme == 'web+mastodon' if uri.scheme == 'web+mastodon'
case uri.host case uri.host
when 'follow' when 'follow'
return redirect_to authorize_interaction_path(uri: uri.query_values['uri'].gsub(/\Aacct:/, '')) return redirect_to authorize_interaction_path(uri: uri.query_values['uri'].delete_prefix('acct:'))
when 'share' when 'share'
return redirect_to share_path(text: uri.query_values['text']) return redirect_to share_path(text: uri.query_values['text'])
end end

View File

@ -13,7 +13,7 @@ module ActivityPub::CaseTransform
when Symbol then camel_lower(value.to_s).to_sym when Symbol then camel_lower(value.to_s).to_sym
when String when String
camel_lower_cache[value] ||= if value.start_with?('_:') camel_lower_cache[value] ||= if value.start_with?('_:')
"_:#{value.gsub(/\A_:/, '').underscore.camelize(:lower)}" "_:#{value.delete_prefix('_:').underscore.camelize(:lower)}"
else else
value.underscore.camelize(:lower) value.underscore.camelize(:lower)
end end

View File

@ -52,7 +52,7 @@ class PermalinkRedirector
end end
def path_segments def path_segments
@path_segments ||= @path.gsub(/\A\//, '').split('/') @path_segments ||= @path.delete_prefix('/').split('/')
end end
def find_status_url_by_id(id) def find_status_url_by_id(id)

View File

@ -57,7 +57,7 @@ class WebfingerResource
end end
def resource_without_acct_string def resource_without_acct_string
resource.gsub(/\Aacct:/, '') resource.delete_prefix('acct:')
end end
def local_username def local_username

View File

@ -67,7 +67,7 @@ class ActivityPub::FetchRemoteActorService < BaseService
end end
def split_acct(acct) def split_acct(acct)
acct.gsub(/\Aacct:/, '').split('@') acct.delete_prefix('acct:').split('@')
end end
def supported_context? def supported_context?

View File

@ -100,7 +100,7 @@ class ResolveAccountService < BaseService
end end
def split_acct(acct) def split_acct(acct)
acct.gsub(/\Aacct:/, '').split('@') acct.delete_prefix('acct:').split('@')
end end
def fetch_account! def fetch_account!

View File

@ -2,7 +2,7 @@
class TagSearchService < BaseService class TagSearchService < BaseService
def call(query, options = {}) def call(query, options = {})
@query = query.strip.gsub(/\A#/, '') @query = query.strip.delete_prefix('#')
@offset = options.delete(:offset).to_i @offset = options.delete(:offset).to_i
@limit = options.delete(:limit).to_i @limit = options.delete(:limit).to_i
@options = options @options = options