From eb51e43fb4386120f77f2ff99581f15018a81bd4 Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Fri, 22 Jan 2021 04:09:08 -0500 Subject: Optimize some regex matching (#15528) * Use Regex#match? * Replace =~ too * Avoid to call match? from Nil * Keep value of Regexp.last_match --- config/initializers/open_uri_redirection.rb | 2 +- config/initializers/rack_attack.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'config/initializers') diff --git a/config/initializers/open_uri_redirection.rb b/config/initializers/open_uri_redirection.rb index e9de85bdc..0e57c53c6 100644 --- a/config/initializers/open_uri_redirection.rb +++ b/config/initializers/open_uri_redirection.rb @@ -3,6 +3,6 @@ require 'open-uri' module OpenURI def self.redirectable?(uri1, uri2) # :nodoc: uri1.scheme.casecmp(uri2.scheme).zero? || - (/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme) + (/\A(?:http|https|ftp)\z/i.match?(uri1.scheme) && /\A(?:http|https|ftp)\z/i.match?(uri2.scheme)) end end diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 6662ef40b..c0db49907 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -78,7 +78,7 @@ class Rack::Attack API_DELETE_STATUS_REGEX = /\A\/api\/v1\/statuses\/[\d]+/.freeze throttle('throttle_api_delete', limit: 30, period: 30.minutes) do |req| - req.authenticated_user_id if (req.post? && req.path =~ API_DELETE_REBLOG_REGEX) || (req.delete? && req.path =~ API_DELETE_STATUS_REGEX) + req.authenticated_user_id if (req.post? && req.path.match?(API_DELETE_REBLOG_REGEX)) || (req.delete? && req.path.match?(API_DELETE_STATUS_REGEX)) end throttle('throttle_sign_up_attempts/ip', limit: 25, period: 5.minutes) do |req| -- cgit