Skip to content
代码片段 群组 项目
提交 38483543 编辑于 作者: Bola Buari's avatar Bola Buari
浏览文件

Fix Performance/RegexpMatch offenses

Changelog: other
EE: true
上级 13892cc8
No related branches found
No related tags found
无相关合并请求
显示
23 个添加23 个删除
......@@ -209,7 +209,7 @@ def to_html
when "nowiki"
return self.element_content
when "a"
if self.element_attributes['href'] =~ /:\/\//
if /:\/\//.match?(self.element_attributes['href'])
return @options[:link_handler].external_link(self.element_attributes['href'], self.element_content)
elsif self.element_attributes['href'].nil? || self.element_attributes['href'] =~ /^\s*([\?\/])/
# if a element has no href attribute, or href starts with / or ?
......
......@@ -25,7 +25,7 @@ def validate_date_params
def valid_utc_date?(date)
return true if date.blank?
return false unless date =~ Gitlab::Regex.utc_date_regex
return false unless Gitlab::Regex.utc_date_regex.match?(date)
return true if Date.parse(date)
rescue Date::Error
......
......@@ -23,7 +23,7 @@ def references_in(text, pattern = object_class.reference_pattern)
end
def unescape_link(href)
return href if href =~ object_class.reference_pattern
return href if object_class.reference_pattern.match?(href)
super
end
......
......@@ -14,7 +14,7 @@ def self.text_before_stop_word(text, stop_word = STOP_REGEX)
def self.extract_keys(input)
input.scan(/\[.*?\]/)
.map { |x| x[1..-2].delete("\"").delete("'") }
.map { |x| x =~ /^(\d)+$/ ? Integer(x) : x }
.map { |x| /^(\d)+$/.match?(x) ? Integer(x) : x }
end
end
end
......
......@@ -8,7 +8,7 @@ def initialize(app)
end
def call(env)
return @app.call(env) if env['PATH_INFO'] =~ %r{^/api/v\d+/internal/}
return @app.call(env) if %r{^/api/v\d+/internal/}.match?(env['PATH_INFO'])
::Gitlab::IpAddressState.with(env['action_dispatch.remote_ip'].to_s) do # rubocop: disable CodeReuse/ActiveRecord
@app.call(env)
......
......@@ -17,7 +17,7 @@
metadata[:with_license] = metadata.fetch(:with_license, true)
location = metadata[:location]
metadata[:geo] = metadata.fetch(:geo, true) if location =~ %r{[/_]geo[/_]}
metadata[:geo] = metadata.fetch(:geo, true) if %r{[/_]geo[/_]}.match?(location)
end
config.define_derived_metadata do |metadata|
......
......@@ -181,7 +181,7 @@ def authorized_project_scope?(project)
def find_pipeline(id)
return unless id
if id.to_s =~ INTEGER_ID_REGEX
if INTEGER_ID_REGEX.match?(id.to_s)
::Ci::Pipeline.find_by(id: id)
end
end
......@@ -210,7 +210,7 @@ def find_organization!(id)
def find_group(id, organization: nil)
collection = organization.present? ? Group.in_organization(organization) : Group.all
if id.to_s =~ INTEGER_ID_REGEX
if INTEGER_ID_REGEX.match?(id.to_s)
collection.find_by(id: id)
else
collection.find_by_full_path(id)
......@@ -250,7 +250,7 @@ def check_namespace_access(namespace)
# find_namespace returns the namespace regardless of user access level on the namespace
# rubocop: disable CodeReuse/ActiveRecord
def find_namespace(id)
if id.to_s =~ INTEGER_ID_REGEX
if INTEGER_ID_REGEX.match?(id.to_s)
Namespace.without_project_namespaces.find_by(id: id)
else
find_namespace_by_path(id)
......
......@@ -27,7 +27,7 @@ def params_with_array_types
options[:route_options][:params].map do |key, val|
param_type = val[:type]
# Search for parameters with Array types (e.g. "[String]", "[Integer]", etc.)
if param_type =~ %r{\[\w*\]}
if %r{\[\w*\]}.match?(param_type)
key
end
end.compact.to_set
......
......@@ -6,7 +6,7 @@ module Validators
module BulkImports
class DestinationSlugPath < Grape::Validations::Validators::Base
def validate_param!(attr_name, params)
return if params[attr_name] =~ Gitlab::Regex.oci_repository_path_regex
return if Gitlab::Regex.oci_repository_path_regex.match?(params[attr_name])
raise Grape::Exceptions::Validation.new(
params: [@scope.full_name(attr_name)],
......
......@@ -40,7 +40,7 @@ module ColorParser
#
# Returns the recognized color String or nil if none was found.
def self.parse(text)
text if COLOR_FORMAT =~ text
text if COLOR_FORMAT.match?(text)
end
end
end
......@@ -77,10 +77,10 @@ def remove_disallowed_ids
return unless node.name == 'a' || node.name == 'div' || SECTION_HEADINGS.any?(node.name)
return unless node.has_attribute?('id')
return if node['id'] =~ PREFIXED_ID_PATTERN
return if PREFIXED_ID_PATTERN.match?(node['id'])
if (pattern = FOOTNOTE_LINK_ID_PATTERNS[node.name.to_sym])
return if node['id'] =~ pattern
return if node['id']&.match?(pattern)
end
node.remove_attribute('id')
......
......@@ -157,7 +157,7 @@ def call
next
end
if link =~ link_pattern_anchor
if link_pattern_anchor.match?(link)
replace_link_node_with_href(node, index, link) do
object_link_filter(link, link_pattern_anchor, link_content: inner_html, link_reference: true)
end
......
......@@ -53,7 +53,7 @@ def call
end
elsif element_node?(node)
yield_valid_link(node) do |link, inner_html|
if link =~ ref_pattern_start
if ref_pattern_start.match?(link)
replace_link_node_with_href(node, index, link) do
object_link_filter(link, ref_pattern_start, link_content: inner_html)
end
......
......@@ -5,7 +5,7 @@ module PathNormalization
private
def normalize_path(path)
return path.downcase if path =~ Gitlab::Regex.oci_repository_path_regex
return path.downcase if Gitlab::Regex.oci_repository_path_regex.match?(path)
path = path.parameterize.downcase
......
......@@ -40,7 +40,7 @@ def validate!
raise Feature::InvalidFeatureFlagError, "Feature flag is missing name"
end
unless VALID_FEATURE_NAME =~ name
unless VALID_FEATURE_NAME.match?(name)
raise Feature::InvalidFeatureFlagError, "Feature flag '#{name}' is invalid"
end
......
......@@ -155,7 +155,7 @@ namespace :gitlab do
# - Dir.entries returns also the entries '.' and '..'
def remove_unneeded_files(directory, regex)
Dir.foreach(directory) do |file|
FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex
FileUtils.rm_rf(File.join(directory, file)) unless regex.match?(file)
end
end
......
......@@ -92,7 +92,7 @@ def sanitize_filename(name)
name = name.tr("\\", "/") # work-around for IE
name = ::File.basename(name)
name = name.gsub(CarrierWave::SanitizedFile.sanitize_regexp, "_")
name = "_#{name}" if name =~ /\A\.+\z/
name = "_#{name}" if /\A\.+\z/.match?(name)
name = "unnamed" if name.empty?
name.mb_chars.to_s
end
......
......@@ -41,7 +41,7 @@ def start_gitlab_connect(project, channel: nil)
chat_page.messages.last.text =~ /connect your GitLab account|404 not found!/i
end
break(true) if chat_page.messages.last.text =~ /404 not found!/i
break(true) if /404 not found!/i.match?(chat_page.messages.last.text)
chat_page.click_connect_account_link
......
......@@ -14,7 +14,7 @@ class Location
def initialize(git_uri)
@git_uri = git_uri
@uri =
if git_uri =~ %r{\A(?:ssh|http|https)://}
if %r{\A(?:ssh|http|https)://}.match?(git_uri)
URI.parse(git_uri)
else
*rest, path = git_uri.split(':')
......
......@@ -117,7 +117,7 @@ def api_post_to(post_path, post_body, args = {})
body = extract_graphql_body(graphql_response)
unless graphql_response.code == HTTP_STATUS_OK && (body[:errors].nil? || body[:errors].empty?)
action = post_body =~ /mutation {\s+destroy/ ? 'Deletion' : 'Fabrication'
action = /mutation {\s+destroy/.match?(post_body) ? 'Deletion' : 'Fabrication'
raise(ResourceFabricationFailedError, <<~MSG.strip)
#{action} of #{self.class.name} using the API failed (#{graphql_response.code}) with `#{graphql_response}`.
#{QA::Support::Loglinking.failure_metadata(graphql_response.headers[:x_request_id])}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册