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:
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/327490
Style/RegexpLiteralMixedPreserve:
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/spec/service/docker_run/gitlab_runner_spec.rb'
- 'rubocop/cop/gitlab/duplicate_spec_location.rb'
......
......@@ -5,7 +5,7 @@ module StatusPage
# 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_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'
......
......@@ -71,7 +71,7 @@ class VulnerabilityPresenter < Gitlab::View::Presenter::Delegated
def path_with_line_number(path)
return unless path
path = path.gsub(/^\//, '')
path = path.gsub(%r{^/}, '')
add_line_numbers(path, finding.location['start_line'], finding.location['end_line'])
end
......
......@@ -25,7 +25,7 @@ module API
end
def update_geo_nodes_endpoint?
request.put? && request.path.match?(/\/geo_nodes\/\d+/)
request.put? && request.path.match?(%r{/geo_nodes/\d+})
end
end
......
......@@ -31,7 +31,7 @@ module Gitlab
path = @data[:blob_path] || @data.dig(:location, :blob_path)
return unless path
path.gsub(/^\//, '')
path.gsub(%r{^/}, '')
end
def location_link
......
......@@ -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 :expires_at, type: DateTime, desc: 'Date string in ISO 8601 format (`YYYY-MM-DDTHH:MM:SSZ`)'
end
put ":id/invitations/:email", requirements: { email: /[^\/]+/ } do
put ":id/invitations/:email", requirements: { email: %r{[^/]+} } do
source = find_source(source_type, params.delete(:id))
invite_email = params[:email]
authorize_admin_source!(source_type, source)
......@@ -88,7 +88,7 @@ module API
params do
requires :email, type: String, desc: 'The email address of the invitation'
end
delete ":id/invitations/:email", requirements: { email: /[^\/]+/ } do
delete ":id/invitations/:email", requirements: { email: %r{[^/]+} } do
source = find_source(source_type, params[:id])
invite_email = params[:email]
authorize_admin_source!(source_type, source)
......
......@@ -11,7 +11,7 @@ module Gitlab
PATTERN = %r{^\/([^\/]|\\/)+[^\\]\/[ismU]*}.freeze
def initialize(regexp)
super(regexp.gsub(/\\\//, '/'))
super(regexp.gsub(%r{\\/}, '/'))
unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value)
raise Lexer::SyntaxError, 'Invalid regular expression!'
......
......@@ -13,7 +13,7 @@ module Gitlab
"put" => %w(200 202 204 400 401 403 404 405 406 409 410 422 500)
}.freeze
HEALTH_ENDPOINT = /^\/-\/(liveness|readiness|health|metrics)\/?$/.freeze
HEALTH_ENDPOINT = %r{^/-/(liveness|readiness|health|metrics)/?$}.freeze
FEATURE_CATEGORY_DEFAULT = 'unknown'
......
......@@ -9,7 +9,7 @@ module Gitlab
IGNORABLE_SQL = %w{BEGIN COMMIT}.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
TRANSACTION_DURATION_BUCKET = [0.1, 0.25, 1].freeze
......
......@@ -184,19 +184,19 @@ module Gitlab
# - Must not have a scheme, such as http:// or https://
# - Must not have a port number, such as :8080 or :8443
@go_package_regex ||= /
@go_package_regex ||= %r{
\b (?# word boundary)
(?<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)
\.[a-z]{2,} (?# top-level domain)
)
(?<path>\/(?:
[-\/$_.+!*'(),0-9a-z] (?# plain URL character)
(?<path>/(?:
[-/$_.+!*'(),0-9a-z] (?# plain URL character)
| %[0-9a-f]{2})* (?# URL encoded character)
)? (?# path)
\b (?# word boundary)
/ix.freeze
}ix.freeze
end
def generic_package_version_regex
......@@ -416,7 +416,7 @@ module Gitlab
end
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
def feature_flag_regex
......
......@@ -13,7 +13,7 @@ module Gitlab
return unless path.is_a?(String)
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)
raise PathTraversalAttackError, 'Invalid path'
......
......@@ -6,6 +6,6 @@ module ProductAnalytics
URL = Gitlab.config.gitlab.url + '/-/sp.js'
# 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
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