Commit 2b6307f6 authored by Takuya Noguchi's avatar Takuya Noguchi

Enable RuboCop Style/RegexpLiteral

parent 08e01343
...@@ -704,7 +704,9 @@ Style/RedundantSelf: ...@@ -704,7 +704,9 @@ Style/RedundantSelf:
# Configuration parameters: EnforcedStyle, AllowInnerSlashes. # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed # SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral: Style/RegexpLiteral:
Enabled: false Enabled: true
EnforcedStyle: mixed
AllowInnerSlashes: false
# Offense count: 36 # Offense count: 36
# Cop supports --auto-correct. # Cop supports --auto-correct.
......
...@@ -5,7 +5,7 @@ class HelpController < ApplicationController ...@@ -5,7 +5,7 @@ class HelpController < ApplicationController
# Taken from Jekyll # Taken from Jekyll
# https://github.com/jekyll/jekyll/blob/3.5-stable/lib/jekyll/document.rb#L13 # https://github.com/jekyll/jekyll/blob/3.5-stable/lib/jekyll/document.rb#L13
YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
def index def index
# Remove YAML frontmatter so that it doesn't look weird # Remove YAML frontmatter so that it doesn't look weird
......
...@@ -403,6 +403,6 @@ class ProjectsController < Projects::ApplicationController ...@@ -403,6 +403,6 @@ class ProjectsController < Projects::ApplicationController
# to # to
# localhost/group/project # localhost/group/project
# #
redirect_to request.original_url.sub(/\.git\/?\Z/, '') if params[:format] == 'git' redirect_to request.original_url.sub(%r{\.git/?\Z}, '') if params[:format] == 'git'
end end
end end
module SidekiqHelper module SidekiqHelper
SIDEKIQ_PS_REGEXP = /\A SIDEKIQ_PS_REGEXP = %r{\A
(?<pid>\d+)\s+ (?<pid>\d+)\s+
(?<cpu>[\d\.,]+)\s+ (?<cpu>[\d\.,]+)\s+
(?<mem>[\d\.,]+)\s+ (?<mem>[\d\.,]+)\s+
(?<state>[DIEKNRSTVWXZNLpsl\+<>\/\d]+)\s+ (?<state>[DIEKNRSTVWXZNLpsl\+<>/\d]+)\s+
(?<start>.+?)\s+ (?<start>.+?)\s+
(?<command>(?:ruby\d+:\s+)?sidekiq.*\].*) (?<command>(?:ruby\d+:\s+)?sidekiq.*\].*)
\z/x \z}x
def parse_sidekiq_ps(line) def parse_sidekiq_ps(line)
match = line.strip.match(SIDEKIQ_PS_REGEXP) match = line.strip.match(SIDEKIQ_PS_REGEXP)
......
...@@ -11,7 +11,7 @@ module SubmoduleHelper ...@@ -11,7 +11,7 @@ module SubmoduleHelper
url = File.join(Gitlab.config.gitlab.url, @project.full_path) url = File.join(Gitlab.config.gitlab.url, @project.full_path)
end end
if url =~ /([^\/:]+)\/([^\/]+(?:\.git)?)\Z/ if url =~ %r{([^/:]+)/([^/]+(?:\.git)?)\Z}
namespace, project = $1, $2 namespace, project = $1, $2
gitlab_hosts = [Gitlab.config.gitlab.url, gitlab_hosts = [Gitlab.config.gitlab.url,
Gitlab.config.gitlab_shell.ssh_path_prefix] Gitlab.config.gitlab_shell.ssh_path_prefix]
...@@ -23,7 +23,7 @@ module SubmoduleHelper ...@@ -23,7 +23,7 @@ module SubmoduleHelper
end end
end end
namespace.sub!(/\A\//, '') namespace.sub!(%r{\A/}, '')
project.rstrip! project.rstrip!
project.sub!(/\.git\z/, '') project.sub!(/\.git\z/, '')
...@@ -47,11 +47,11 @@ module SubmoduleHelper ...@@ -47,11 +47,11 @@ module SubmoduleHelper
protected protected
def github_dot_com_url?(url) def github_dot_com_url?(url)
url =~ /github\.com[\/:][^\/]+\/[^\/]+\Z/ url =~ %r{github\.com[/:][^/]+/[^/]+\Z}
end end
def gitlab_dot_com_url?(url) def gitlab_dot_com_url?(url)
url =~ /gitlab\.com[\/:][^\/]+\/[^\/]+\Z/ url =~ %r{gitlab\.com[/:][^/]+/[^/]+\Z}
end end
def self_url?(url, namespace, project) def self_url?(url, namespace, project)
...@@ -65,7 +65,7 @@ module SubmoduleHelper ...@@ -65,7 +65,7 @@ module SubmoduleHelper
def relative_self_url?(url) def relative_self_url?(url)
# (./)?(../repo.git) || (./)?(../../project/repo.git) ) # (./)?(../repo.git) || (./)?(../../project/repo.git) )
url =~ /\A((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*(\.git)?\z/ || url =~ /\A((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*(\.git)?\z/ url =~ %r{\A((\./)?(\.\./))(?!(\.\.)|(.*/)).*(\.git)?\z} || url =~ %r{\A((\./)?(\.\./){2})(?!(\.\.))([^/]*)/(?!(\.\.)|(.*/)).*(\.git)?\z}
end end
def standard_links(host, namespace, project, commit) def standard_links(host, namespace, project, commit)
......
...@@ -110,7 +110,7 @@ module TreeHelper ...@@ -110,7 +110,7 @@ module TreeHelper
# returns the relative path of the first subdir that doesn't have only one directory descendant # returns the relative path of the first subdir that doesn't have only one directory descendant
def flatten_tree(root_path, tree) def flatten_tree(root_path, tree)
return tree.flat_path.sub(/\A#{root_path}\//, '') if tree.flat_path.present? return tree.flat_path.sub(%r{\A#{root_path}/}, '') if tree.flat_path.present?
subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path) subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
if subtree.count == 1 && subtree.first.dir? if subtree.count == 1 && subtree.first.dir?
......
...@@ -292,7 +292,7 @@ module Ci ...@@ -292,7 +292,7 @@ module Ci
def repo_url def repo_url
auth = "gitlab-ci-token:#{ensure_token!}@" auth = "gitlab-ci-token:#{ensure_token!}@"
project.http_url_to_repo.sub(/^https?:\/\//) do |prefix| project.http_url_to_repo.sub(%r{^https?://}) do |prefix|
prefix + auth prefix + auth
end end
end end
......
...@@ -141,7 +141,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -141,7 +141,7 @@ class CommitStatus < ActiveRecord::Base
end end
def group_name def group_name
name.to_s.gsub(/\d+[\s:\/\\]+\d+\s*/, '').strip name.to_s.gsub(%r{\d+[\s:/\\]+\d+\s*}, '').strip
end end
def failed_but_allowed? def failed_but_allowed?
......
...@@ -9,13 +9,13 @@ require 'task_list/filter' ...@@ -9,13 +9,13 @@ require 'task_list/filter'
module Taskable module Taskable
COMPLETED = 'completed'.freeze COMPLETED = 'completed'.freeze
INCOMPLETE = 'incomplete'.freeze INCOMPLETE = 'incomplete'.freeze
ITEM_PATTERN = / ITEM_PATTERN = %r{
^ ^
\s*(?:[-+*]|(?:\d+\.)) # list prefix required - task item has to be always in a list \s*(?:[-+*]|(?:\d+\.)) # list prefix required - task item has to be always in a list
\s+ # whitespace prefix has to be always presented for a list item \s+ # whitespace prefix has to be always presented for a list item
(\[\s\]|\[[xX]\]) # checkbox (\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text. (\s.+) # followed by whitespace and some text.
/x }x
def self.get_tasks(content) def self.get_tasks(content)
content.to_s.scan(ITEM_PATTERN).map do |checkbox, label| content.to_s.scan(ITEM_PATTERN).map do |checkbox, label|
......
...@@ -115,7 +115,7 @@ class Environment < ActiveRecord::Base ...@@ -115,7 +115,7 @@ class Environment < ActiveRecord::Base
def formatted_external_url def formatted_external_url
return nil unless external_url return nil unless external_url
external_url.gsub(/\A.*?:\/\//, '') external_url.gsub(%r{\A.*?://}, '')
end end
def stop_action? def stop_action?
......
...@@ -234,7 +234,7 @@ class Project < ActiveRecord::Base ...@@ -234,7 +234,7 @@ class Project < ActiveRecord::Base
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
validates :description, length: { maximum: 2000 }, allow_blank: true validates :description, length: { maximum: 2000 }, allow_blank: true
validates :ci_config_path, validates :ci_config_path,
format: { without: /(\.{2}|\A\/)/, format: { without: %r{(\.{2}|\A/)},
message: 'cannot include leading slash or directory traversal.' }, message: 'cannot include leading slash or directory traversal.' },
length: { maximum: 255 }, length: { maximum: 255 },
allow_blank: true allow_blank: true
...@@ -1338,7 +1338,7 @@ class Project < ActiveRecord::Base ...@@ -1338,7 +1338,7 @@ class Project < ActiveRecord::Base
host = "#{subdomain}.#{Settings.pages.host}".downcase host = "#{subdomain}.#{Settings.pages.host}".downcase
# The host in URL always needs to be downcased # The host in URL always needs to be downcased
url = Gitlab.config.pages.url.sub(/^https?:\/\//) do |prefix| url = Gitlab.config.pages.url.sub(%r{^https?://}) do |prefix|
"#{prefix}#{subdomain}." "#{prefix}#{subdomain}."
end.downcase end.downcase
......
...@@ -84,7 +84,7 @@ http://app.asana.com/-/account_api' ...@@ -84,7 +84,7 @@ http://app.asana.com/-/account_api'
# - fix/ed/es/ing # - fix/ed/es/ing
# - close/s/d # - close/s/d
# - closing # - closing
issue_finder = /(fix\w*|clos[ei]\w*+)?\W*(?:https:\/\/app\.asana\.com\/\d+\/\d+\/(\d+)|#(\d+))/i issue_finder = %r{(fix\w*|clos[ei]\w*+)?\W*(?:https://app\.asana\.com/\d+/\d+/(\d+)|#(\d+))}i
message.scan(issue_finder).each do |tuple| message.scan(issue_finder).each do |tuple|
# tuple will be # tuple will be
......
...@@ -10,9 +10,9 @@ class IssueTrackerService < Service ...@@ -10,9 +10,9 @@ class IssueTrackerService < Service
# overriden patterns. See ReferenceRegexes::EXTERNAL_PATTERN # overriden patterns. See ReferenceRegexes::EXTERNAL_PATTERN
def self.reference_pattern(only_long: false) def self.reference_pattern(only_long: false)
if only_long if only_long
%r{(\b[A-Z][A-Z0-9_]+-)(?<issue>\d+)} /(\b[A-Z][A-Z0-9_]+-)(?<issue>\d+)/
else else
%r{(\b[A-Z][A-Z0-9_]+-|#{Issue.reference_prefix})(?<issue>\d+)} /(\b[A-Z][A-Z0-9_]+-|#{Issue.reference_prefix})(?<issue>\d+)/
end end
end end
......
...@@ -19,7 +19,7 @@ class JiraService < IssueTrackerService ...@@ -19,7 +19,7 @@ class JiraService < IssueTrackerService
# {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1 # {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1
def self.reference_pattern(only_long: true) def self.reference_pattern(only_long: true)
@reference_pattern ||= %r{(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)} @reference_pattern ||= /(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)/
end end
def initialize_properties def initialize_properties
......
...@@ -842,13 +842,13 @@ class User < ActiveRecord::Base ...@@ -842,13 +842,13 @@ class User < ActiveRecord::Base
end end
def full_website_url def full_website_url
return "http://#{website_url}" if website_url !~ /\Ahttps?:\/\// return "http://#{website_url}" if website_url !~ %r{\Ahttps?://}
website_url website_url
end end
def short_website_url def short_website_url
website_url.sub(/\Ahttps?:\/\//, '') website_url.sub(%r{\Ahttps?://}, '')
end end
def all_ssh_keys def all_ssh_keys
......
---
title: Enable RuboCop Style/RegexpLiteral
merge_request: 16752
author: Takuya Noguchi
type: other
...@@ -110,7 +110,7 @@ class Settings < Settingslogic ...@@ -110,7 +110,7 @@ class Settings < Settingslogic
url = "http://#{url}" unless url.start_with?('http') url = "http://#{url}" unless url.start_with?('http')
# Get rid of the path so that we don't even have to encode it # Get rid of the path so that we don't even have to encode it
url_without_path = url.sub(%r{(https?://[^\/]+)/?.*}, '\1') url_without_path = url.sub(%r{(https?://[^/]+)/?.*}, '\1')
URI.parse(url_without_path).host URI.parse(url_without_path).host
end end
...@@ -469,10 +469,10 @@ end ...@@ -469,10 +469,10 @@ end
# repository_downloads_path value. # repository_downloads_path value.
# #
repositories_storages = Settings.repositories.storages.values repositories_storages = Settings.repositories.storages.values
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(/\/$/, '') repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(%r{/$}, '')
repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home']) repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home'])
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(/\/$/, '')) } if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(%r{/$}, '')) }
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive') Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive')
end end
......
...@@ -54,7 +54,7 @@ elsif Gitlab::Database.mysql? ...@@ -54,7 +54,7 @@ elsif Gitlab::Database.mysql?
def initialize_type_map(mapping) def initialize_type_map(mapping)
super mapping super mapping
mapping.register_type(%r(timestamp)i) do |sql_type| mapping.register_type(/timestamp/i) do |sql_type|
precision = extract_precision(sql_type) precision = extract_precision(sql_type)
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTimeWithTimeZone.new(precision: precision) ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTimeWithTimeZone.new(precision: precision)
end end
......
namespace :admin do namespace :admin do
resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do resources :users, constraints: { id: %r{[a-zA-Z./0-9_\-]+} } do
resources :keys, only: [:show, :destroy] resources :keys, only: [:show, :destroy]
resources :identities, except: [:show] resources :identities, except: [:show]
resources :impersonation_tokens, only: [:index, :create] do resources :impersonation_tokens, only: [:index, :create] do
......
...@@ -35,7 +35,7 @@ constraints(GroupUrlConstrainer.new) do ...@@ -35,7 +35,7 @@ constraints(GroupUrlConstrainer.new) do
post :toggle_subscription, on: :member post :toggle_subscription, on: :member
end end
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :edit, :update, :new, :create] do resources :milestones, constraints: { id: %r{[^/]+} }, only: [:index, :show, :edit, :update, :new, :create] do
member do member do
get :merge_requests get :merge_requests
get :participants get :participants
...@@ -52,7 +52,7 @@ constraints(GroupUrlConstrainer.new) do ...@@ -52,7 +52,7 @@ constraints(GroupUrlConstrainer.new) do
resources :uploads, only: [:create] do resources :uploads, only: [:create] do
collection do collection do
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ } get ":secret/:filename", action: :show, as: :show, constraints: { filename: %r{[^/]+} }
end end
end end
end end
......
...@@ -40,7 +40,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -40,7 +40,7 @@ constraints(ProjectUrlConstrainer.new) do
# #
# Templates # Templates
# #
get '/templates/:template_type/:key' => 'templates#show', as: :template, constraints: { key: /[^\/]+/ } get '/templates/:template_type/:key' => 'templates#show', as: :template, constraints: { key: %r{[^/]+} }
resource :avatar, only: [:show, :destroy] resource :avatar, only: [:show, :destroy]
resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
...@@ -55,7 +55,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -55,7 +55,7 @@ constraints(ProjectUrlConstrainer.new) do
end end
resource :pages, only: [:show, :destroy] do resource :pages, only: [:show, :destroy] do
resources :domains, only: [:show, :new, :create, :destroy], controller: 'pages_domains', constraints: { id: /[^\/]+/ } resources :domains, only: [:show, :new, :create, :destroy], controller: 'pages_domains', constraints: { id: %r{[^/]+} }
end end
resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do
...@@ -65,7 +65,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -65,7 +65,7 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do resources :services, constraints: { id: %r{[^/]+} }, only: [:index, :edit, :update] do
member do member do
put :test put :test
end end
...@@ -346,7 +346,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -346,7 +346,7 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
resources :project_members, except: [:show, :new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ }, concerns: :access_requestable do resources :project_members, except: [:show, :new, :edit], constraints: { id: %r{[a-zA-Z./0-9_\-#%+]+} }, concerns: :access_requestable do
collection do collection do
delete :leave delete :leave
...@@ -379,7 +379,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -379,7 +379,7 @@ constraints(ProjectUrlConstrainer.new) do
resources :uploads, only: [:create] do resources :uploads, only: [:create] do
collection do collection do
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ } get ":secret/:filename", action: :show, as: :show, constraints: { filename: %r{[^/]+} }
end end
end end
......
...@@ -2,17 +2,17 @@ scope path: :uploads do ...@@ -2,17 +2,17 @@ scope path: :uploads do
# Note attachments and User/Group/Project avatars # Note attachments and User/Group/Project avatars
get "-/system/:model/:mounted_as/:id/:filename", get "-/system/:model/:mounted_as/:id/:filename",
to: "uploads#show", to: "uploads#show",
constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /[^\/]+/ } constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: %r{[^/]+} }
# show uploads for models, snippets (notes) available for now # show uploads for models, snippets (notes) available for now
get '-/system/:model/:id/:secret/:filename', get '-/system/:model/:id/:secret/:filename',
to: 'uploads#show', to: 'uploads#show',
constraints: { model: /personal_snippet/, id: /\d+/, filename: /[^\/]+/ } constraints: { model: /personal_snippet/, id: /\d+/, filename: %r{[^/]+} }
# show temporary uploads # show temporary uploads
get '-/system/temp/:secret/:filename', get '-/system/temp/:secret/:filename',
to: 'uploads#show', to: 'uploads#show',
constraints: { filename: /[^\/]+/ } constraints: { filename: %r{[^/]+} }
# Appearance # Appearance
get "-/system/:model/:mounted_as/:id/:filename", get "-/system/:model/:mounted_as/:id/:filename",
...@@ -22,7 +22,7 @@ scope path: :uploads do ...@@ -22,7 +22,7 @@ scope path: :uploads do
# Project markdown uploads # Project markdown uploads
get ":namespace_id/:project_id/:secret/:filename", get ":namespace_id/:project_id/:secret/:filename",
to: "projects/uploads#show", to: "projects/uploads#show",
constraints: { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ } constraints: { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: %r{[^/]+} }
# create uploads for models, snippets (notes) available for now # create uploads for models, snippets (notes) available for now
post ':model', post ':model',
...@@ -34,4 +34,4 @@ end ...@@ -34,4 +34,4 @@ end
# Redirect old note attachments path to new uploads path. # Redirect old note attachments path to new uploads path.
get "files/note/:id/:filename", get "files/note/:id/:filename",
to: redirect("uploads/note/attachment/%{id}/%{filename}"), to: redirect("uploads/note/attachment/%{id}/%{filename}"),
constraints: { filename: /[^\/]+/ } constraints: { filename: %r{[^/]+} }
...@@ -193,7 +193,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps ...@@ -193,7 +193,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
end end
step 'The link with text "/ID" should have url "tree/markdownID"' do step 'The link with text "/ID" should have url "tree/markdownID"' do
find('a', text: /^\/#id$/)['href'] == current_host + project_tree_path(@project, "markdown") + '#id' find('a', text: %r{^/#id$})['href'] == current_host + project_tree_path(@project, "markdown") + '#id'
end end
step 'The link with text "README.mdID" '\ step 'The link with text "README.mdID" '\
...@@ -203,7 +203,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps ...@@ -203,7 +203,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'The link with text "d/README.mdID" should have '\ step 'The link with text "d/README.mdID" should have '\
'url "blob/markdown/d/README.mdID"' do 'url "blob/markdown/d/README.mdID"' do
find('a', text: /^d\/README.md#id$/)['href'] == current_host + project_blob_path(@project, "d/markdown/README.md") + '#id' find('a', text: %r{^d/README.md#id$})['href'] == current_host + project_blob_path(@project, "d/markdown/README.md") + '#id'
end end
step 'The link with text "ID" should have url "blob/markdown/README.mdID"' do step 'The link with text "ID" should have url "blob/markdown/README.mdID"' do
...@@ -212,7 +212,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps ...@@ -212,7 +212,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
end end
step 'The link with text "/ID" should have url "blob/markdown/README.mdID"' do step 'The link with text "/ID" should have url "blob/markdown/README.mdID"' do
find('a', text: /^\/#id$/)['href'] == current_host + project_blob_path(@project, "markdown/README.md") + '#id' find('a', text: %r{^/#id$})['href'] == current_host + project_blob_path(@project, "markdown/README.md") + '#id'
end end
# Wiki # Wiki
......
...@@ -17,15 +17,15 @@ module API ...@@ -17,15 +17,15 @@ module API
} }
}.freeze }.freeze
PROJECT_TEMPLATE_REGEX = PROJECT_TEMPLATE_REGEX =
/[\<\{\[] %r{[\<\{\[]
(project|description| (project|description|
one\sline\s.+\swhat\sit\sdoes\.) # matching the start and end is enough here one\sline\s.+\swhat\sit\sdoes\.) # matching the start and end is enough here
[\>\}\]]/xi.freeze [\>\}\]]}xi.freeze
YEAR_TEMPLATE_REGEX = /[<{\[](year|yyyy)[>}\]]/i.freeze YEAR_TEMPLATE_REGEX = /[<{\[](year|yyyy)[>}\]]/i.freeze
FULLNAME_TEMPLATE_REGEX = FULLNAME_TEMPLATE_REGEX =
/[\<\{\[] %r{[\<\{\[]
(fullname|name\sof\s(author|copyright\sowner)) (fullname|name\sof\s(author|copyright\sowner))
[\>\}\]]/xi.freeze [\>\}\]]}xi.freeze
helpers do helpers do
def parsed_license_template def parsed_license_template
......
...@@ -173,7 +173,7 @@ module API ...@@ -173,7 +173,7 @@ module API
use :sort_params use :sort_params
use :pagination use :pagination
end end
get "/search/:query", requirements: { query: /[^\/]+/ } do get "/search/:query", requirements: { query: %r{[^/]+} } do
search_service = Search::GlobalService.new(current_user, search: params[:query]).execute search_service = Search::GlobalService.new(current_user, search: params[:query]).execute
projects = search_service.objects('projects', params[:page], false) projects = search_service.objects('projects', params[:page], false)
projects = projects.reorder(params[:order_by] => params[:sort]) projects = projects.reorder(params[:order_by] => params[:sort])
......
...@@ -16,15 +16,15 @@ module API ...@@ -16,15 +16,15 @@ module API
} }
}.freeze }.freeze
PROJECT_TEMPLATE_REGEX = PROJECT_TEMPLATE_REGEX =
/[\<\{\[] %r{[\<\{\[]
(project|description| (project|description|
one\sline\s.+\swhat\sit\sdoes\.) # matching the start and end is enough here one\sline\s.+\swhat\sit\sdoes\.) # matching the start and end is enough here
[\>\}\]]/xi.freeze [\>\}\]]}xi.freeze
YEAR_TEMPLATE_REGEX = /[<{\[](year|yyyy)[>}\]]/i.freeze YEAR_TEMPLATE_REGEX = /[<{\[](year|yyyy)[>}\]]/i.freeze
FULLNAME_TEMPLATE_REGEX = FULLNAME_TEMPLATE_REGEX =
/[\<\{\[] %r{[\<\{\[]
(fullname|name\sof\s(author|copyright\sowner)) (fullname|name\sof\s(author|copyright\sowner))
[\>\}\]]/xi.freeze [\>\}\]]}xi.freeze
DEPRECATION_MESSAGE = ' This endpoint is deprecated and has been removed in V4.'.freeze DEPRECATION_MESSAGE = ' This endpoint is deprecated and has been removed in V4.'.freeze
helpers do helpers do
......
...@@ -54,9 +54,9 @@ module Banzai ...@@ -54,9 +54,9 @@ module Banzai
# Build a regexp that matches all valid :emoji: names. # Build a regexp that matches all valid :emoji: names.
def self.emoji_pattern def self.emoji_pattern
@emoji_pattern ||= @emoji_pattern ||=
/(?<=[^[:alnum:]:]|\n|^) %r{(?<=[^[:alnum:]:]|\n|^)
:(#{Gitlab::Emoji.emojis_names.map { |name| Regexp.escape(name) }.join('|')}): :(#{Gitlab::Emoji.emojis_names.map { |name| Regexp.escape(name) }.join('|')}):
(?=[^[:alnum:]:]|$)/x (?=[^[:alnum:]:]|$)}x
end end
# Build a regexp that matches all valid unicode emojis names. # Build a regexp that matches all valid unicode emojis names.
......
...@@ -51,10 +51,10 @@ module Banzai ...@@ -51,10 +51,10 @@ module Banzai
# See https://github.com/gollum/gollum/wiki # See https://github.com/gollum/gollum/wiki
# #
# Rubular: http://rubular.com/r/7dQnE5CUCH # Rubular: http://rubular.com/r/7dQnE5CUCH
TAGS_PATTERN = %r{\[\[(.+?)\]\]}.freeze TAGS_PATTERN = /\[\[(.+?)\]\]/.freeze
# Pattern to match allowed image extensions # Pattern to match allowed image extensions
ALLOWED_IMAGE_EXTENSIONS = %r{.+(jpg|png|gif|svg|bmp)\z}i.freeze ALLOWED_IMAGE_EXTENSIONS = /.+(jpg|png|gif|svg|bmp)\z/i.freeze
def call def call
search_text_nodes(doc).each do |node| search_text_nodes(doc).each do |node|
......
...@@ -11,7 +11,7 @@ module ContainerRegistry ...@@ -11,7 +11,7 @@ module ContainerRegistry
private private
def default_path def default_path
@uri.sub(/^https?:\/\//, '') @uri.sub(%r{^https?://}, '')
end end
end end
end end
...@@ -56,7 +56,7 @@ module ExtractsPath ...@@ -56,7 +56,7 @@ module ExtractsPath
if valid_refs.length == 0 if valid_refs.length == 0
# No exact ref match, so just try our best # No exact ref match, so just try our best
pair = id.match(/([^\/]+)(.*)/).captures pair = id.match(%r{([^/]+)(.*)}).captures
else else
# There is a distinct possibility that multiple refs prefix the ID. # There is a distinct possibility that multiple refs prefix the ID.
# Use the longest match to maximize the chance that we have the # Use the longest match to maximize the chance that we have the
...@@ -68,7 +68,7 @@ module ExtractsPath ...@@ -68,7 +68,7 @@ module ExtractsPath
end end
# Remove ending slashes from path # Remove ending slashes from path
pair[1].gsub!(/^\/|\/$/, '') pair[1].gsub!(%r{^/|/$}, '')
pair pair
end end
......
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
# Ends with /:random_hex/:filename # Ends with /:random_hex/:filename
FILE_UPLOADER_PATH = %r{/\h+/[^/]+\z} FILE_UPLOADER_PATH = %r{/\h+/[^/]+\z}
FULL_PATH_CAPTURE = %r{\A(.+)#{FILE_UPLOADER_PATH}} FULL_PATH_CAPTURE = /\A(.+)#{FILE_UPLOADER_PATH}/
# These regex patterns are tested against a relative path, relative to # These regex patterns are tested against a relative path, relative to
# the upload directory. # the upload directory.
......
...@@ -97,7 +97,7 @@ module Gitlab ...@@ -97,7 +97,7 @@ module Gitlab
end end
def total_size def total_size
descendant_pattern = %r{^#{Regexp.escape(@path.to_s)}} descendant_pattern = /^#{Regexp.escape(@path.to_s)}/
entries.sum do |path, entry| entries.sum do |path, entry|
(entry[:size] if path =~ descendant_pattern).to_i (entry[:size] if path =~ descendant_pattern).to_i
end end
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
end end
def package_url(name) def package_url(name)
"https://packagist.org/packages/#{name}" if name =~ %r{\A#{REPO_REGEX}\z} "https://packagist.org/packages/#{name}" if name =~ /\A#{REPO_REGEX}\z/
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
link_regex(/(github:|:github\s*=>)\s*['"](?<name>[^'"]+)['"]/, &method(:github_url)) link_regex(/(github:|:github\s*=>)\s*['"](?<name>[^'"]+)['"]/, &method(:github_url))
# Link `git: "https://gitlab.example.com/user/repo"` to https://gitlab.example.com/user/repo # Link `git: "https://gitlab.example.com/user/repo"` to https://gitlab.example.com/user/repo
link_regex(%r{(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]}, &:itself) link_regex(/(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]/, &:itself)
# Link `source "https://rubygems.org"` to https://rubygems.org # Link `source "https://rubygems.org"` to https://rubygems.org
link_method_call('source', URL_REGEX, &:itself) link_method_call('source', URL_REGEX, &:itself)
......
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
def link_dependencies def link_dependencies
link_method_call('homepage', URL_REGEX, &:itself) link_method_call('homepage', URL_REGEX, &:itself)
link_regex(%r{(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]}, &:itself) link_regex(/(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]/, &:itself)
link_method_call('license', &method(:license_url)) link_method_call('license', &method(:license_url))
link_regex(/license\s*=\s*\{\s*(type:|:type\s*=>)\s*#{STRING_REGEX}/, &method(:license_url)) link_regex(/license\s*=\s*\{\s*(type:|:type\s*=>)\s*#{STRING_REGEX}/, &method(:license_url))
......
...@@ -43,7 +43,7 @@ module Gitlab ...@@ -43,7 +43,7 @@ module Gitlab
return "" unless decoded return "" unless decoded
# Certain trigger phrases that means we didn't parse correctly # Certain trigger phrases that means we didn't parse correctly
if decoded =~ /(Content\-Type\:|multipart\/alternative|text\/plain)/ if decoded =~ %r{(Content\-Type\:|multipart/alternative|text/plain)}
return "" return ""
end end
......
...@@ -6,14 +6,14 @@ module Gitlab ...@@ -6,14 +6,14 @@ module Gitlab
module FileDetector module FileDetector
PATTERNS = { PATTERNS = {
# Project files # Project files
readme: /\Areadme[^\/]*\z/i, readme: %r{\Areadme[^/]*\z}i,
changelog: /\A(changelog|history|changes|news)[^\/]*\z/i, changelog: %r{\A(changelog|history|changes|news)[^/]*\z}i,
license: /\A(licen[sc]e|copying)(\.[^\/]+)?\z/i, license: %r{\A(licen[sc]e|copying)(\.[^/]+)?\z}i,
contributing: /\Acontributing[^\/]*\z/i, contributing: %r{\Acontributing[^/]*\z}i,
version: 'version', version: 'version',
avatar: /\Alogo\.(png|jpg|gif)\z/, avatar: /\Alogo\.(png|jpg|gif)\z/,
issue_template: /\A\.gitlab\/issue_templates\/[^\/]+\.md\z/, issue_template: %r{\A\.gitlab/issue_templates/[^/]+\.md\z},
merge_request_template: /\A\.gitlab\/merge_request_templates\/[^\/]+\.md\z/, merge_request_template: %r{\A\.gitlab/merge_request_templates/[^/]+\.md\z},
# Configuration files # Configuration files
gitignore: '.gitignore', gitignore: '.gitignore',
...@@ -22,17 +22,17 @@ module Gitlab ...@@ -22,17 +22,17 @@ module Gitlab
route_map: '.gitlab/route-map.yml', route_map: '.gitlab/route-map.yml',
# Dependency files # Dependency files
cartfile: /\ACartfile[^\/]*\z/, cartfile: %r{\ACartfile[^/]*\z},
composer_json: 'composer.json', composer_json: 'composer.json',
gemfile: /\A(Gemfile|gems\.rb)\z/, gemfile: /\A(Gemfile|gems\.rb)\z/,
gemfile_lock: 'Gemfile.lock', gemfile_lock: 'Gemfile.lock',
gemspec: /\A[^\/]*\.gemspec\z/, gemspec: %r{\A[^/]*\.gemspec\z},
godeps_json: 'Godeps.json', godeps_json: 'Godeps.json',
package_json: 'package.json', package_json: 'package.json',
podfile: 'Podfile', podfile: 'Podfile',
podspec_json: /\A[^\/]*\.podspec\.json\z/, podspec_json: %r{\A[^/]*\.podspec\.json\z},
podspec: /\A[^\/]*\.podspec\z/, podspec: %r{\A[^/]*\.podspec\z},
requirements_txt: /\A[^\/]*requirements\.txt\z/, requirements_txt: %r{\A[^/]*requirements\.txt\z},
yarn_lock: 'yarn.lock' yarn_lock: 'yarn.lock'
}.freeze }.freeze
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
include Gitlab::EncodingHelper include Gitlab::EncodingHelper
def ref_name(ref) def ref_name(ref)
encode!(ref).sub(/\Arefs\/(tags|heads|remotes)\//, '') encode!(ref).sub(%r{\Arefs/(tags|heads|remotes)/}, '')
end end
def branch_name(ref) def branch_name(ref)
......
...@@ -107,7 +107,7 @@ module Gitlab ...@@ -107,7 +107,7 @@ module Gitlab
def find_entry_by_path(repository, root_id, path) def find_entry_by_path(repository, root_id, path)
root_tree = repository.lookup(root_id) root_tree = repository.lookup(root_id)
# Strip leading slashes # Strip leading slashes
path[/^\/*/] = '' path[%r{^/*}] = ''
path_arr = path.split('/') path_arr = path.split('/')
entry = root_tree.find do |entry| entry = root_tree.find do |entry|
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE)
return unless path return unless path
path = path.sub(/\A\/*/, '') path = path.sub(%r{\A/*}, '')
path = '/' if path.empty? path = '/' if path.empty?
name = File.basename(path) name = File.basename(path)
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
class << self class << self
def normalize_path(filename) def normalize_path(filename)
# Strip all leading slashes so that //foo -> foo # Strip all leading slashes so that //foo -> foo
filename[/^\/*/] = '' filename[%r{^/*}] = ''
# Expand relative paths (e.g. foo/../bar) # Expand relative paths (e.g. foo/../bar)
filename = Pathname.new(filename) filename = Pathname.new(filename)
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
# Ex. # Ex.
# Ref.extract_branch_name('refs/heads/master') #=> 'master' # Ref.extract_branch_name('refs/heads/master') #=> 'master'
def self.extract_branch_name(str) def self.extract_branch_name(str)
str.gsub(/\Arefs\/heads\//, '') str.gsub(%r{\Arefs/heads/}, '')
end end
# Gitaly: this method will probably be migrated indirectly via its call sites. # Gitaly: this method will probably be migrated indirectly via its call sites.
......
...@@ -1397,7 +1397,7 @@ module Gitlab ...@@ -1397,7 +1397,7 @@ module Gitlab
end end
def search_files_by_name(query, ref) def search_files_by_name(query, ref)
safe_query = Regexp.escape(query.sub(/^\/*/, "")) safe_query = Regexp.escape(query.sub(%r{^/*}, ""))
return [] if empty? || safe_query.blank? return [] if empty? || safe_query.blank?
...@@ -2025,7 +2025,7 @@ module Gitlab ...@@ -2025,7 +2025,7 @@ module Gitlab
target_commit = Gitlab::Git::Commit.find(self, rugged_ref.target) target_commit = Gitlab::Git::Commit.find(self, rugged_ref.target)
Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target, target_commit) Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target, target_commit)
rescue Rugged::ReferenceError => e rescue Rugged::ReferenceError => e
raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/ raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ %r{'refs/heads/#{ref}'}
raise InvalidRef.new("Invalid reference #{start_point}") raise InvalidRef.new("Invalid reference #{start_point}")
end end
......
...@@ -43,7 +43,7 @@ module Gitlab ...@@ -43,7 +43,7 @@ module Gitlab
branches = [] branches = []
rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref| rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref|
name = ref.name.sub(/\Arefs\/remotes\/#{remote_name}\//, '') name = ref.name.sub(%r{\Arefs/remotes/#{remote_name}/}, '')
begin begin
target_commit = Gitlab::Git::Commit.find(self, ref.target) target_commit = Gitlab::Git::Commit.find(self, ref.target)
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
:diff_hunk, :author, :note, :created_at, :updated_at, :diff_hunk, :author, :note, :created_at, :updated_at,
:github_id :github_id
NOTEABLE_ID_REGEX = /\/pull\/(?<iid>\d+)/i NOTEABLE_ID_REGEX = %r{/pull/(?<iid>\d+)}i
# Builds a diff note from a GitHub API response. # Builds a diff note from a GitHub API response.
# #
......
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
expose_attribute :noteable_id, :noteable_type, :author, :note, expose_attribute :noteable_id, :noteable_type, :author, :note,
:created_at, :updated_at, :github_id :created_at, :updated_at, :github_id
NOTEABLE_TYPE_REGEX = /\/(?<type>(pull|issues))\/(?<iid>\d+)/i NOTEABLE_TYPE_REGEX = %r{/(?<type>(pull|issues))/(?<iid>\d+)}i
# Builds a note from a GitHub API response. # Builds a note from a GitHub API response.
# #
......
...@@ -59,7 +59,7 @@ module Gitlab ...@@ -59,7 +59,7 @@ module Gitlab
end end
def extracted_files def extracted_files
Dir.glob("#{@shared.export_path}/**/*", File::FNM_DOTMATCH).reject { |f| f =~ /.*\/\.{1,2}$/ } Dir.glob("#{@shared.export_path}/**/*", File::FNM_DOTMATCH).reject { |f| f =~ %r{.*/\.{1,2}$} }
end end
end end
end end
......
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
end end
def relative_path(path) def relative_path(path)
path.gsub(/^#{Rails.root.to_s}\/?/, '') path.gsub(%r{^#{Rails.root.to_s}/?}, '')
end end
def values_for(event) def values_for(event)
......
...@@ -56,12 +56,12 @@ module Gitlab ...@@ -56,12 +56,12 @@ module Gitlab
end end
def strip_url(url) def strip_url(url)
url.gsub(/\Ahttps?:\/\//, '') url.gsub(%r{\Ahttps?://}, '')
end end
def project_path(request) def project_path(request)
path_info = request.env["PATH_INFO"] path_info = request.env["PATH_INFO"]
path_info.sub!(/^\//, '') path_info.sub!(%r{^/}, '')
project_path_match = "#{path_info}/".match(PROJECT_PATH_REGEX) project_path_match = "#{path_info}/".match(PROJECT_PATH_REGEX)
return unless project_path_match return unless project_path_match
......
module Gitlab module Gitlab
module Middleware module Middleware
class Static < ActionDispatch::Static class Static < ActionDispatch::Static
UPLOADS_REGEX = /\A\/uploads(\/|\z)/.freeze UPLOADS_REGEX = %r{\A/uploads(/|\z)}.freeze
def call(env) def call(env)
return @app.call(env) if env['PATH_INFO'] =~ UPLOADS_REGEX return @app.call(env) if env['PATH_INFO'] =~ UPLOADS_REGEX
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
# if date doesn't present return time with current date # if date doesn't present return time with current date
# in other cases return nil # in other cases return nil
class SpendTimeAndDateSeparator class SpendTimeAndDateSeparator
DATE_REGEX = /(\d{2,4}[\/\-.]\d{1,2}[\/\-.]\d{1,2})/ DATE_REGEX = %r{(\d{2,4}[/\-.]\d{1,2}[/\-.]\d{1,2})}
def initialize(spend_command_arg) def initialize(spend_command_arg)
@spend_arg = spend_command_arg @spend_arg = spend_command_arg
......
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
raise NotFoundError.new("No known storage path matches #{repo_path.inspect}") raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
end end
result.sub(/\A\/*/, '') result.sub(%r{\A/*}, '')
end end
def self.find_project(project_path) def self.find_project(project_path)
......
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
storages << { name: 'test_second_storage', path: Rails.root.join('tmp', 'tests', 'second_storage').to_s } storages << { name: 'test_second_storage', path: Rails.root.join('tmp', 'tests', 'second_storage').to_s }
end end
config = { socket_path: address.sub(%r{\Aunix:}, ''), storage: storages } config = { socket_path: address.sub(/\Aunix:/, ''), storage: storages }
config[:auth] = { token: 'secret' } if Rails.env.test? config[:auth] = { token: 'secret' } if Rails.env.test?
config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby
config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path } config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path }
......
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
end end
def relative_path def relative_path
@relative_path ||= @file.gsub(/^#{Rails.root.to_s}\/?/, '') @relative_path ||= @file.gsub(%r{^#{Rails.root.to_s}/?}, '')
end end
def to_param def to_param
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module Sherlock module Sherlock
# Rack middleware used for tracking request metrics. # Rack middleware used for tracking request metrics.
class Middleware class Middleware
CONTENT_TYPES = /text\/html|application\/json/i CONTENT_TYPES = %r{text/html|application/json}i
IGNORE_PATHS = %r{^/sherlock} IGNORE_PATHS = %r{^/sherlock}
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
attr_reader :id, :query, :started_at, :finished_at, :backtrace attr_reader :id, :query, :started_at, :finished_at, :backtrace
# SQL identifiers that should be prefixed with newlines. # SQL identifiers that should be prefixed with newlines.
PREFIX_NEWLINE = / PREFIX_NEWLINE = %r{
\s+(FROM \s+(FROM
|(LEFT|RIGHT)?INNER\s+JOIN |(LEFT|RIGHT)?INNER\s+JOIN
|(LEFT|RIGHT)?OUTER\s+JOIN |(LEFT|RIGHT)?OUTER\s+JOIN
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
|GROUP\s+BY |GROUP\s+BY
|ORDER\s+BY |ORDER\s+BY
|LIMIT |LIMIT
|OFFSET)\s+/ix # Vim indent breaks when this is on a newline :< |OFFSET)\s+}ix # Vim indent breaks when this is on a newline :<
# Creates a new Query using a String and a separate Array of bindings. # Creates a new Query using a String and a separate Array of bindings.
# #
......
...@@ -49,7 +49,7 @@ module Gitlab ...@@ -49,7 +49,7 @@ module Gitlab
def fetch_git_tags def fetch_git_tags
remote_tags, _ = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} ls-remote --tags https://gitlab.com/gitlab-org/gitlab-ce.git)) remote_tags, _ = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} ls-remote --tags https://gitlab.com/gitlab-org/gitlab-ce.git))
remote_tags.split("\n").grep(/tags\/v#{current_version.major}/) remote_tags.split("\n").grep(%r{tags/v#{current_version.major}})
end end
def update_commands def update_commands
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
element :settings_link, 'link_to edit_project_path' element :settings_link, 'link_to edit_project_path'
element :repository_link, "title: 'Repository'" element :repository_link, "title: 'Repository'"
element :pipelines_settings_link, "title: 'CI / CD'" element :pipelines_settings_link, "title: 'CI / CD'"
element :issues_link, %r{link_to.*shortcuts-issues} element :issues_link, /link_to.*shortcuts-issues/
element :issues_link_text, "Issues" element :issues_link_text, "Issues"
element :top_level_items, '.sidebar-top-level-items' element :top_level_items, '.sidebar-top-level-items'
element :activity_link, "title: 'Activity'" element :activity_link, "title: 'Activity'"
......
...@@ -3,7 +3,7 @@ describe QA::Runtime::RSAKey do ...@@ -3,7 +3,7 @@ describe QA::Runtime::RSAKey do
subject { described_class.new.public_key } subject { described_class.new.public_key }
it 'generates a public RSA key' do it 'generates a public RSA key' do
expect(subject).to match(/\Assh\-rsa AAAA[0-9A-Za-z+\/]+={0,3}\z/) expect(subject).to match(%r{\Assh\-rsa AAAA[0-9A-Za-z+/]+={0,3}\z})
end end
end end
end end
...@@ -29,7 +29,7 @@ module RuboCop ...@@ -29,7 +29,7 @@ module RuboCop
path = Pathname.new(source_name).relative_path_from(rails_root) path = Pathname.new(source_name).relative_path_from(rails_root)
dirname = File.dirname(path) dirname = File.dirname(path)
.sub(%r{\Adb/(migrate|post_migrate)}, 'spec/migrations') .sub(%r{\Adb/(migrate|post_migrate)}, 'spec/migrations')
filename = File.basename(source_name, '.rb').sub(%r{\A\d+_}, '') filename = File.basename(source_name, '.rb').sub(/\A\d+_/, '')
File.join(dirname, "#{filename}_spec.rb") File.join(dirname, "#{filename}_spec.rb")
end end
......
...@@ -137,8 +137,8 @@ describe Projects::JobsController do ...@@ -137,8 +137,8 @@ describe Projects::JobsController do
it 'exposes needed information' do it 'exposes needed information' do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['raw_path']).to match(/jobs\/\d+\/raw\z/) expect(json_response['raw_path']).to match(%r{jobs/\d+/raw\z})
expect(json_response.dig('merge_request', 'path')).to match(/merge_requests\/\d+\z/) expect(json_response.dig('merge_request', 'path')).to match(%r{merge_requests/\d+\z})
expect(json_response['new_issue_path']) expect(json_response['new_issue_path'])
.to include('/issues/new') .to include('/issues/new')
end end
......
...@@ -36,7 +36,7 @@ describe Projects::TodosController do ...@@ -36,7 +36,7 @@ describe Projects::TodosController do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['count']).to eq 1 expect(json_response['count']).to eq 1
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}})
end end
end end
...@@ -104,7 +104,7 @@ describe Projects::TodosController do ...@@ -104,7 +104,7 @@ describe Projects::TodosController do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['count']).to eq 1 expect(json_response['count']).to eq 1
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}})
end end
end end
......
...@@ -64,7 +64,7 @@ describe "User Feed" do ...@@ -64,7 +64,7 @@ describe "User Feed" do
end end
it 'has XHTML summaries in issue descriptions' do it 'has XHTML summaries in issue descriptions' do
expect(body).to match /<hr ?\/>/ expect(body).to match %r{<hr ?/>}
end end
it 'has XHTML summaries in notes' do it 'has XHTML summaries in notes' do
...@@ -72,7 +72,7 @@ describe "User Feed" do ...@@ -72,7 +72,7 @@ describe "User Feed" do
end end
it 'has XHTML summaries in merge request descriptions' do it 'has XHTML summaries in merge request descriptions' do
expect(body).to match /Here is the fix: <a[^>]*><img[^>]*\/><\/a>/ expect(body).to match %r{Here is the fix: <a[^>]*><img[^>]*/></a>}
end end
it 'has push event commit ID' do it 'has push event commit ID' do
......
...@@ -100,12 +100,12 @@ describe 'Merge request > User resolves conflicts', :js do ...@@ -100,12 +100,12 @@ describe 'Merge request > User resolves conflicts', :js do
end end
it 'shows a link to the conflict resolution page' do it 'shows a link to the conflict resolution page' do
expect(page).to have_link('conflicts', href: /\/conflicts\Z/) expect(page).to have_link('conflicts', href: %r{/conflicts\Z})
end end
context 'in Inline view mode' do context 'in Inline view mode' do
before do before do
click_link('conflicts', href: /\/conflicts\Z/) click_link('conflicts', href: %r{/conflicts\Z})
end end
include_examples "conflicts are resolved in Interactive mode" include_examples "conflicts are resolved in Interactive mode"
...@@ -114,7 +114,7 @@ describe 'Merge request > User resolves conflicts', :js do ...@@ -114,7 +114,7 @@ describe 'Merge request > User resolves conflicts', :js do
context 'in Parallel view mode' do context 'in Parallel view mode' do
before do before do
click_link('conflicts', href: /\/conflicts\Z/) click_link('conflicts', href: %r{/conflicts\Z})
click_button 'Side-by-side' click_button 'Side-by-side'
end end
...@@ -128,7 +128,7 @@ describe 'Merge request > User resolves conflicts', :js do ...@@ -128,7 +128,7 @@ describe 'Merge request > User resolves conflicts', :js do
before do before do
visit project_merge_request_path(project, merge_request) visit project_merge_request_path(project, merge_request)
click_link('conflicts', href: /\/conflicts\Z/) click_link('conflicts', href: %r{/conflicts\Z})
end end
it 'conflicts can not be resolved in Interactive mode' do it 'conflicts can not be resolved in Interactive mode' do
...@@ -181,7 +181,7 @@ describe 'Merge request > User resolves conflicts', :js do ...@@ -181,7 +181,7 @@ describe 'Merge request > User resolves conflicts', :js do
end end
it 'does not show a link to the conflict resolution page' do it 'does not show a link to the conflict resolution page' do
expect(page).not_to have_link('conflicts', href: /\/conflicts\Z/) expect(page).not_to have_link('conflicts', href: %r{/conflicts\Z})
end end
it 'shows an error if the conflicts page is visited directly' do it 'shows an error if the conflicts page is visited directly' do
......
...@@ -105,7 +105,7 @@ describe GroupsHelper do ...@@ -105,7 +105,7 @@ describe GroupsHelper do
it 'outputs the groups in the correct order' do it 'outputs the groups in the correct order' do
expect(helper.group_title(very_deep_nested_group)) expect(helper.group_title(very_deep_nested_group))
.to match(/<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*<\/li>.*<a.*>#{very_deep_nested_group.name}<\/a>/m) .to match(%r{<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
end end
end end
...@@ -120,7 +120,7 @@ describe GroupsHelper do ...@@ -120,7 +120,7 @@ describe GroupsHelper do
let(:possible_help_texts) do let(:possible_help_texts) do
{ {
default_help: "This setting will be applied to all subgroups unless overridden by a group owner", default_help: "This setting will be applied to all subgroups unless overridden by a group owner",
ancestor_locked_but_you_can_override: /This setting is applied on <a .+>.+<\/a>\. You can override the setting or .+/, ancestor_locked_but_you_can_override: %r{This setting is applied on <a .+>.+</a>\. You can override the setting or .+},
ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/, ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/,
ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/ ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/
} }
......
...@@ -104,7 +104,7 @@ describe LabelsHelper do ...@@ -104,7 +104,7 @@ describe LabelsHelper do
context 'with a tooltip argument' do context 'with a tooltip argument' do
context 'set to false' do context 'set to false' do
it 'does not include the has-tooltip class' do it 'does not include the has-tooltip class' do
expect(link_to_label(label, tooltip: false)).not_to match %r{has-tooltip} expect(link_to_label(label, tooltip: false)).not_to match /has-tooltip/
end end
end end
end end
......
...@@ -27,7 +27,7 @@ describe VersionCheckHelper do ...@@ -27,7 +27,7 @@ describe VersionCheckHelper do
end end
it 'should have a VersionCheck url as the src' do it 'should have a VersionCheck url as the src' do
expect(@image_tag).to match(/src="https:\/\/version\.host\.com\/check\.svg\?gitlab_info=xxx"/) expect(@image_tag).to match(%r{src="https://version\.host\.com/check\.svg\?gitlab_info=xxx"})
end end
end end
end end
......
...@@ -53,7 +53,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter do ...@@ -53,7 +53,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter do
doc = reference_filter("See (#{reference}.)") doc = reference_filter("See (#{reference}.)")
exp = Regexp.escape(range.reference_link_text) exp = Regexp.escape(range.reference_link_text)
expect(doc.to_html).to match(/\(<a.+>#{exp}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{exp}</a>\.\)})
end end
it 'ignores invalid commit IDs' do it 'ignores invalid commit IDs' do
...@@ -222,7 +222,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter do ...@@ -222,7 +222,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter do
doc = reference_filter("Fixed (#{reference}.)") doc = reference_filter("Fixed (#{reference}.)")
exp = Regexp.escape(range.reference_link_text(project)) exp = Regexp.escape(range.reference_link_text(project))
expect(doc.to_html).to match(/\(<a.+>#{exp}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{exp}</a>\.\)})
end end
it 'ignores invalid commit IDs on the referenced project' do it 'ignores invalid commit IDs on the referenced project' do
......
...@@ -42,7 +42,7 @@ describe Banzai::Filter::CommitReferenceFilter do ...@@ -42,7 +42,7 @@ describe Banzai::Filter::CommitReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("See (#{reference}.)") doc = reference_filter("See (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{commit.short_id}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{commit.short_id}</a>\.\)})
end end
it 'ignores invalid commit IDs' do it 'ignores invalid commit IDs' do
...@@ -199,12 +199,12 @@ describe Banzai::Filter::CommitReferenceFilter do ...@@ -199,12 +199,12 @@ describe Banzai::Filter::CommitReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Fixed (#{reference}.)") doc = reference_filter("Fixed (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{commit.reference_link_text(project)}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{commit.reference_link_text(project)}</a>\.\)})
end end
it 'ignores invalid commit IDs on the referenced project' do it 'ignores invalid commit IDs on the referenced project' do
act = "Committed #{invalidate_reference(reference)}" act = "Committed #{invalidate_reference(reference)}"
expect(reference_filter(act).to_html).to match(/<a.+>#{Regexp.escape(invalidate_reference(reference))}<\/a>/) expect(reference_filter(act).to_html).to match(%r{<a.+>#{Regexp.escape(invalidate_reference(reference))}</a>})
end end
end end
end end
...@@ -49,7 +49,7 @@ describe Banzai::Filter::ExternalIssueReferenceFilter do ...@@ -49,7 +49,7 @@ describe Banzai::Filter::ExternalIssueReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = filter("Issue (#{reference}.)") doc = filter("Issue (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{reference}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{reference}</a>\.\)})
end end
it 'includes a title attribute' do it 'includes a title attribute' do
......
...@@ -14,7 +14,7 @@ describe Banzai::Filter::ImageLinkFilter do ...@@ -14,7 +14,7 @@ describe Banzai::Filter::ImageLinkFilter do
it 'does not wrap a duplicate link' do it 'does not wrap a duplicate link' do
doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>)) doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>))
expect(doc.to_html).to match /^<a href="\/whatever"><img[^>]*><\/a>$/ expect(doc.to_html).to match %r{^<a href="/whatever"><img[^>]*></a>$}
end end
it 'works with external images' do it 'works with external images' do
...@@ -24,6 +24,6 @@ describe Banzai::Filter::ImageLinkFilter do ...@@ -24,6 +24,6 @@ describe Banzai::Filter::ImageLinkFilter do
it 'works with inline images' do it 'works with inline images' do
doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>)) doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>))
expect(doc.to_html).to match /^<p>test <a[^>]*><img[^>]*><\/a> inline<\/p>$/ expect(doc.to_html).to match %r{^<p>test <a[^>]*><img[^>]*></a> inline</p>$}
end end
end end
...@@ -288,7 +288,7 @@ describe Banzai::Filter::IssueReferenceFilter do ...@@ -288,7 +288,7 @@ describe Banzai::Filter::IssueReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Fixed (#{reference}.)") doc = reference_filter("Fixed (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(issue.to_reference(project))} \(comment 123\)<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(issue.to_reference(project))} \(comment 123\)</a>\.\)})
end end
it 'includes default classes' do it 'includes default classes' do
...@@ -317,7 +317,7 @@ describe Banzai::Filter::IssueReferenceFilter do ...@@ -317,7 +317,7 @@ describe Banzai::Filter::IssueReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Fixed (#{reference_link}.)") doc = reference_filter("Fixed (#{reference_link}.)")
expect(doc.to_html).to match(/\(<a.+>Reference<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>Reference</a>\.\)})
end end
it 'includes default classes' do it 'includes default classes' do
...@@ -346,7 +346,7 @@ describe Banzai::Filter::IssueReferenceFilter do ...@@ -346,7 +346,7 @@ describe Banzai::Filter::IssueReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Fixed (#{reference_link}.)") doc = reference_filter("Fixed (#{reference_link}.)")
expect(doc.to_html).to match(/\(<a.+>Reference<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>Reference</a>\.\)})
end end
it 'includes default classes' do it 'includes default classes' do
......
...@@ -42,7 +42,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter do ...@@ -42,7 +42,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Merge (#{reference}.)") doc = reference_filter("Merge (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(reference)}</a>\.\)})
end end
it 'ignores invalid merge IDs' do it 'ignores invalid merge IDs' do
...@@ -211,7 +211,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter do ...@@ -211,7 +211,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Merge (#{reference}.)") doc = reference_filter("Merge (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(merge.to_reference(project))} \(diffs, comment 123\)<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(merge.to_reference(project))} \(diffs, comment 123\)</a>\.\)})
end end
end end
......
...@@ -28,7 +28,7 @@ describe Banzai::Filter::SnippetReferenceFilter do ...@@ -28,7 +28,7 @@ describe Banzai::Filter::SnippetReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Snippet (#{reference}.)") doc = reference_filter("Snippet (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(reference)}</a>\.\)})
end end
it 'ignores invalid snippet IDs' do it 'ignores invalid snippet IDs' do
...@@ -192,13 +192,13 @@ describe Banzai::Filter::SnippetReferenceFilter do ...@@ -192,13 +192,13 @@ describe Banzai::Filter::SnippetReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("See (#{reference}.)") doc = reference_filter("See (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(snippet.to_reference(project))}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(snippet.to_reference(project))}</a>\.\)})
end end
it 'ignores invalid snippet IDs on the referenced project' do it 'ignores invalid snippet IDs on the referenced project' do
act = "See #{invalidate_reference(reference)}" act = "See #{invalidate_reference(reference)}"
expect(reference_filter(act).to_html).to match(/<a.+>#{Regexp.escape(invalidate_reference(reference))}<\/a>/) expect(reference_filter(act).to_html).to match(%r{<a.+>#{Regexp.escape(invalidate_reference(reference))}</a>})
end end
end end
......
...@@ -146,7 +146,7 @@ describe Banzai::Filter::UserReferenceFilter do ...@@ -146,7 +146,7 @@ describe Banzai::Filter::UserReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Mention me (#{reference}.)") doc = reference_filter("Mention me (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{reference}<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>#{reference}</a>\.\)})
end end
it 'includes default classes' do it 'includes default classes' do
...@@ -172,7 +172,7 @@ describe Banzai::Filter::UserReferenceFilter do ...@@ -172,7 +172,7 @@ describe Banzai::Filter::UserReferenceFilter do
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Mention me (#{reference}.)") doc = reference_filter("Mention me (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>User<\/a>\.\)/) expect(doc.to_html).to match(%r{\(<a.+>User</a>\.\)})
end end
it 'includes a data-user attribute' do it 'includes a data-user attribute' do
......
...@@ -249,7 +249,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -249,7 +249,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
shared_examples 'archive check' do |extenstion| shared_examples 'archive check' do |extenstion|
it { expect(metadata['ArchivePath']).to match(/tmp\/gitlab-git-test.git\/gitlab-git-test-master-#{SeedRepo::LastCommit::ID}/) } it { expect(metadata['ArchivePath']).to match(%r{tmp/gitlab-git-test.git/gitlab-git-test-master-#{SeedRepo::LastCommit::ID}}) }
it { expect(metadata['ArchivePath']).to end_with extenstion } it { expect(metadata['ArchivePath']).to end_with extenstion }
end end
......
...@@ -121,7 +121,7 @@ describe Gitlab::PathRegex do ...@@ -121,7 +121,7 @@ describe Gitlab::PathRegex do
STARTING_WITH_NAMESPACE = %r{^/\*namespace_id/:(project_)?id} STARTING_WITH_NAMESPACE = %r{^/\*namespace_id/:(project_)?id}
NON_PARAM_PARTS = %r{[^:*][a-z\-_/]*} NON_PARAM_PARTS = %r{[^:*][a-z\-_/]*}
ANY_OTHER_PATH_PART = %r{[a-z\-_/:]*} ANY_OTHER_PATH_PART = %r{[a-z\-_/:]*}
WILDCARD_SEGMENT = %r{\*} WILDCARD_SEGMENT = /\*/
let(:namespaced_wildcard_routes) do let(:namespaced_wildcard_routes) do
routes_without_format.select do |p| routes_without_format.select do |p|
p =~ %r{#{STARTING_WITH_NAMESPACE}/#{NON_PARAM_PARTS}/#{ANY_OTHER_PATH_PART}#{WILDCARD_SEGMENT}} p =~ %r{#{STARTING_WITH_NAMESPACE}/#{NON_PARAM_PARTS}/#{ANY_OTHER_PATH_PART}#{WILDCARD_SEGMENT}}
......
...@@ -1357,7 +1357,7 @@ describe Notify do ...@@ -1357,7 +1357,7 @@ describe Notify do
matcher :have_part_with do |expected| matcher :have_part_with do |expected|
match do |actual| match do |actual|
actual.body.parts.any? { |part| part.content_type.try(:match, %r(#{expected})) } actual.body.parts.any? { |part| part.content_type.try(:match, /#{expected}/) }
end end
end end
end end
......
...@@ -205,7 +205,7 @@ describe JiraService do ...@@ -205,7 +205,7 @@ describe JiraService do
@jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project)) @jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with( expect(WebMock).to have_requested(:post, @comment_url).with(
body: /#{custom_base_url}\/#{project.full_path}\/commit\/#{merge_request.diff_head_sha}/ body: %r{#{custom_base_url}/#{project.full_path}/commit/#{merge_request.diff_head_sha}}
).once ).once
end end
...@@ -220,7 +220,7 @@ describe JiraService do ...@@ -220,7 +220,7 @@ describe JiraService do
@jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project)) @jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with( expect(WebMock).to have_requested(:post, @comment_url).with(
body: /#{Gitlab.config.gitlab.url}\/#{project.full_path}\/commit\/#{merge_request.diff_head_sha}/ body: %r{#{Gitlab.config.gitlab.url}/#{project.full_path}/commit/#{merge_request.diff_head_sha}}
).once ).once
end end
......
...@@ -43,7 +43,7 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do ...@@ -43,7 +43,7 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
it 'creates a system note' do it 'creates a system note' do
note = merge_request.notes.last note = merge_request.notes.last
expect(note.note).to match /enabled an automatic merge when the pipeline for (\w+\/\w+@)?\h{8}/ expect(note.note).to match %r{enabled an automatic merge when the pipeline for (\w+/\w+@)?\h{8}}
end end
end end
......
...@@ -308,7 +308,7 @@ describe SystemNoteService do ...@@ -308,7 +308,7 @@ describe SystemNoteService do
end end
it "posts the 'merge when pipeline succeeds' system note" do it "posts the 'merge when pipeline succeeds' system note" do
expect(subject.note).to match(/enabled an automatic merge when the pipeline for (\w+\/\w+@)?\h{40} succeeds/) expect(subject.note).to match(%r{enabled an automatic merge when the pipeline for (\w+/\w+@)?\h{40} succeeds})
end end
end end
...@@ -695,7 +695,7 @@ describe SystemNoteService do ...@@ -695,7 +695,7 @@ describe SystemNoteService do
commit = double(title: '<pre>This is a test</pre>', short_id: '12345678') commit = double(title: '<pre>This is a test</pre>', short_id: '12345678')
escaped = '&lt;pre&gt;This is a test&lt;&#x2F;pre&gt;' escaped = '&lt;pre&gt;This is a test&lt;&#x2F;pre&gt;'
expect(described_class.new_commit_summary([commit])).to all(match(%r[- #{escaped}])) expect(described_class.new_commit_summary([commit])).to all(match(/- #{escaped}/))
end end
end end
......
...@@ -165,7 +165,7 @@ describe 'gitlab:app namespace rake task' do ...@@ -165,7 +165,7 @@ describe 'gitlab:app namespace rake task' do
expect(tar_contents).to match('pages.tar.gz') expect(tar_contents).to match('pages.tar.gz')
expect(tar_contents).to match('lfs.tar.gz') expect(tar_contents).to match('lfs.tar.gz')
expect(tar_contents).to match('registry.tar.gz') expect(tar_contents).to match('registry.tar.gz')
expect(tar_contents).not_to match(/^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|pages.tar.gz|artifacts.tar.gz|registry.tar.gz)\/$/) expect(tar_contents).not_to match(%r{^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|pages.tar.gz|artifacts.tar.gz|registry.tar.gz)/$})
end end
it 'deletes temp directories' do it 'deletes temp directories' do
......
...@@ -19,7 +19,7 @@ describe 'gitlab:git rake tasks' do ...@@ -19,7 +19,7 @@ describe 'gitlab:git rake tasks' do
describe 'fsck' do describe 'fsck' do
it 'outputs the integrity check for a repo' do it 'outputs the integrity check for a repo' do
expect { run_rake_task('gitlab:git:fsck') }.to output(/Performed Checking integrity at .*@hashed\/1\/2\/test.git/).to_stdout expect { run_rake_task('gitlab:git:fsck') }.to output(%r{Performed Checking integrity at .*@hashed/1/2/test.git}).to_stdout
end end
it 'errors out about config.lock issues' do it 'errors out about config.lock issues' do
......
...@@ -112,7 +112,7 @@ describe FileUploader do ...@@ -112,7 +112,7 @@ describe FileUploader do
fixture = Rails.root.join('spec', 'fixtures', 'rails_sample.jpg') fixture = Rails.root.join('spec', 'fixtures', 'rails_sample.jpg')
uploader.store!(fixture_file_upload(fixture)) uploader.store!(fixture_file_upload(fixture))
expect(uploader.relative_path).to match(/\A\h{32}\/rails_sample.jpg\z/) expect(uploader.relative_path).to match(%r{\A\h{32}/rails_sample.jpg\z})
end end
end end
end end
...@@ -12,7 +12,7 @@ describe JobArtifactUploader do ...@@ -12,7 +12,7 @@ describe JobArtifactUploader do
context 'when using local storage' do context 'when using local storage' do
it { is_expected.to start_with(local_path) } it { is_expected.to start_with(local_path) }
it { is_expected.to match(/\h{2}\/\h{2}\/\h{64}\/\d{4}_\d{1,2}_\d{1,2}\/\d+\/\d+\z/) } it { is_expected.to match(%r{\h{2}/\h{2}/\h{64}/\d{4}_\d{1,2}_\d{1,2}/\d+/\d+\z}) }
it { is_expected.to end_with(path) } it { is_expected.to end_with(path) }
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