Commit c61e4166 authored by Siddharth Asthana's avatar Siddharth Asthana

Fix the offenses introduced by Style/RegexpLiteralMixedPreserve

Changelog: other
EE: true
parent d26b12d6
...@@ -2600,17 +2600,6 @@ Gitlab/FeatureAvailableUsage: ...@@ -2600,17 +2600,6 @@ Gitlab/FeatureAvailableUsage:
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/327490 # WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/327490
Style/RegexpLiteralMixedPreserve: Style/RegexpLiteralMixedPreserve:
Exclude: Exclude:
- 'ee/app/models/status_page/project_setting.rb'
- 'ee/app/presenters/vulnerability_presenter.rb'
- 'ee/lib/api/geo_nodes.rb'
- 'ee/lib/gitlab/vulnerabilities/standard_vulnerability.rb'
- 'lib/api/invitations.rb'
- 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb'
- 'lib/gitlab/metrics/requests_rack_middleware.rb'
- 'lib/gitlab/metrics/subscribers/active_record.rb'
- 'lib/gitlab/regex.rb'
- 'lib/gitlab/utils.rb'
- 'lib/product_analytics/tracker.rb'
- 'qa/qa/page/project/settings/advanced.rb' - 'qa/qa/page/project/settings/advanced.rb'
- 'qa/spec/service/docker_run/gitlab_runner_spec.rb' - 'qa/spec/service/docker_run/gitlab_runner_spec.rb'
- 'rubocop/cop/gitlab/duplicate_spec_location.rb' - 'rubocop/cop/gitlab/duplicate_spec_location.rb'
......
...@@ -5,7 +5,7 @@ module StatusPage ...@@ -5,7 +5,7 @@ module StatusPage
# AWS validations. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25863#note_295772553 # AWS validations. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25863#note_295772553
AWS_BUCKET_NAME_REGEXP = /\A[a-z0-9][a-z0-9\-.]*\z/.freeze AWS_BUCKET_NAME_REGEXP = /\A[a-z0-9][a-z0-9\-.]*\z/.freeze
AWS_ACCESS_KEY_REGEXP = /\A[A-Z0-9]{20}\z/.freeze AWS_ACCESS_KEY_REGEXP = /\A[A-Z0-9]{20}\z/.freeze
AWS_SECRET_KEY_REGEXP = /\A[A-Za-z0-9\/+=]{40}\z/.freeze AWS_SECRET_KEY_REGEXP = %r{\A[A-Za-z0-9/+=]{40}\z}.freeze
self.table_name = 'status_page_settings' self.table_name = 'status_page_settings'
......
...@@ -71,7 +71,7 @@ class VulnerabilityPresenter < Gitlab::View::Presenter::Delegated ...@@ -71,7 +71,7 @@ class VulnerabilityPresenter < Gitlab::View::Presenter::Delegated
def path_with_line_number(path) def path_with_line_number(path)
return unless path return unless path
path = path.gsub(/^\//, '') path = path.gsub(%r{^/}, '')
add_line_numbers(path, finding.location['start_line'], finding.location['end_line']) add_line_numbers(path, finding.location['start_line'], finding.location['end_line'])
end end
......
...@@ -25,7 +25,7 @@ module API ...@@ -25,7 +25,7 @@ module API
end end
def update_geo_nodes_endpoint? def update_geo_nodes_endpoint?
request.put? && request.path.match?(/\/geo_nodes\/\d+/) request.put? && request.path.match?(%r{/geo_nodes/\d+})
end end
end end
......
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
path = @data[:blob_path] || @data.dig(:location, :blob_path) path = @data[:blob_path] || @data.dig(:location, :blob_path)
return unless path return unless path
path.gsub(/^\//, '') path.gsub(%r{^/}, '')
end end
def location_link def location_link
......
...@@ -59,7 +59,7 @@ module API ...@@ -59,7 +59,7 @@ module API
optional :access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'A valid access level (defaults: `30`, developer access level)' optional :access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'A valid access level (defaults: `30`, developer access level)'
optional :expires_at, type: DateTime, desc: 'Date string in ISO 8601 format (`YYYY-MM-DDTHH:MM:SSZ`)' optional :expires_at, type: DateTime, desc: 'Date string in ISO 8601 format (`YYYY-MM-DDTHH:MM:SSZ`)'
end end
put ":id/invitations/:email", requirements: { email: /[^\/]+/ } do put ":id/invitations/:email", requirements: { email: %r{[^/]+} } do
source = find_source(source_type, params.delete(:id)) source = find_source(source_type, params.delete(:id))
invite_email = params[:email] invite_email = params[:email]
authorize_admin_source!(source_type, source) authorize_admin_source!(source_type, source)
...@@ -88,7 +88,7 @@ module API ...@@ -88,7 +88,7 @@ module API
params do params do
requires :email, type: String, desc: 'The email address of the invitation' requires :email, type: String, desc: 'The email address of the invitation'
end end
delete ":id/invitations/:email", requirements: { email: /[^\/]+/ } do delete ":id/invitations/:email", requirements: { email: %r{[^/]+} } do
source = find_source(source_type, params[:id]) source = find_source(source_type, params[:id])
invite_email = params[:email] invite_email = params[:email]
authorize_admin_source!(source_type, source) authorize_admin_source!(source_type, source)
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
PATTERN = %r{^\/([^\/]|\\/)+[^\\]\/[ismU]*}.freeze PATTERN = %r{^\/([^\/]|\\/)+[^\\]\/[ismU]*}.freeze
def initialize(regexp) def initialize(regexp)
super(regexp.gsub(/\\\//, '/')) super(regexp.gsub(%r{\\/}, '/'))
unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value) unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value)
raise Lexer::SyntaxError, 'Invalid regular expression!' raise Lexer::SyntaxError, 'Invalid regular expression!'
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
"put" => %w(200 202 204 400 401 403 404 405 406 409 410 422 500) "put" => %w(200 202 204 400 401 403 404 405 406 409 410 422 500)
}.freeze }.freeze
HEALTH_ENDPOINT = /^\/-\/(liveness|readiness|health|metrics)\/?$/.freeze HEALTH_ENDPOINT = %r{^/-/(liveness|readiness|health|metrics)/?$}.freeze
FEATURE_CATEGORY_DEFAULT = 'unknown' FEATURE_CATEGORY_DEFAULT = 'unknown'
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
IGNORABLE_SQL = %w{BEGIN COMMIT}.freeze IGNORABLE_SQL = %w{BEGIN COMMIT}.freeze
DB_COUNTERS = %i{db_count db_write_count db_cached_count}.freeze DB_COUNTERS = %i{db_count db_write_count db_cached_count}.freeze
SQL_COMMANDS_WITH_COMMENTS_REGEX = /\A(\/\*.*\*\/\s)?((?!(.*[^\w'"](DELETE|UPDATE|INSERT INTO)[^\w'"])))(WITH.*)?(SELECT)((?!(FOR UPDATE|FOR SHARE)).)*$/i.freeze SQL_COMMANDS_WITH_COMMENTS_REGEX = %r{\A(/\*.*\*/\s)?((?!(.*[^\w'"](DELETE|UPDATE|INSERT INTO)[^\w'"])))(WITH.*)?(SELECT)((?!(FOR UPDATE|FOR SHARE)).)*$}i.freeze
SQL_DURATION_BUCKET = [0.05, 0.1, 0.25].freeze SQL_DURATION_BUCKET = [0.05, 0.1, 0.25].freeze
TRANSACTION_DURATION_BUCKET = [0.1, 0.25, 1].freeze TRANSACTION_DURATION_BUCKET = [0.1, 0.25, 1].freeze
......
...@@ -184,19 +184,19 @@ module Gitlab ...@@ -184,19 +184,19 @@ module Gitlab
# - Must not have a scheme, such as http:// or https:// # - Must not have a scheme, such as http:// or https://
# - Must not have a port number, such as :8080 or :8443 # - Must not have a port number, such as :8080 or :8443
@go_package_regex ||= / @go_package_regex ||= %r{
\b (?# word boundary) \b (?# word boundary)
(?<domain> (?<domain>
[0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])? (?# first domain) [0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])? (?# first domain)
(?:\.[0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])?)* (?# inner domains) (?:\.[0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])?)* (?# inner domains)
\.[a-z]{2,} (?# top-level domain) \.[a-z]{2,} (?# top-level domain)
) )
(?<path>\/(?: (?<path>/(?:
[-\/$_.+!*'(),0-9a-z] (?# plain URL character) [-/$_.+!*'(),0-9a-z] (?# plain URL character)
| %[0-9a-f]{2})* (?# URL encoded character) | %[0-9a-f]{2})* (?# URL encoded character)
)? (?# path) )? (?# path)
\b (?# word boundary) \b (?# word boundary)
/ix.freeze }ix.freeze
end end
def generic_package_version_regex def generic_package_version_regex
...@@ -416,7 +416,7 @@ module Gitlab ...@@ -416,7 +416,7 @@ module Gitlab
end end
def base64_regex def base64_regex
@base64_regex ||= /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/.freeze @base64_regex ||= %r{(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?}.freeze
end end
def feature_flag_regex def feature_flag_regex
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
return unless path.is_a?(String) return unless path.is_a?(String)
path = decode_path(path) path = decode_path(path)
path_regex = /(\A(\.{1,2})\z|\A\.\.[\/\\]|[\/\\]\.\.\z|[\/\\]\.\.[\/\\]|\n)/ path_regex = %r{(\A(\.{1,2})\z|\A\.\.[/\\]|[/\\]\.\.\z|[/\\]\.\.[/\\]|\n)}
if path.match?(path_regex) if path.match?(path_regex)
raise PathTraversalAttackError, 'Invalid path' raise PathTraversalAttackError, 'Invalid path'
......
...@@ -6,6 +6,6 @@ module ProductAnalytics ...@@ -6,6 +6,6 @@ module ProductAnalytics
URL = Gitlab.config.gitlab.url + '/-/sp.js' URL = Gitlab.config.gitlab.url + '/-/sp.js'
# The collector URL minus protocol and /i # The collector URL minus protocol and /i
COLLECTOR_URL = Gitlab.config.gitlab.url.sub(/\Ahttps?\:\/\//, '') + '/-/collector' COLLECTOR_URL = Gitlab.config.gitlab.url.sub(%r{\Ahttps?\://}, '') + '/-/collector'
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment