Skip to content

Commit

Permalink
Fix Style/RedundantRegexpEscape cop
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver committed Mar 21, 2024
1 parent d309c1f commit 6656415
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/models/architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def bootfilename_efi
when /aarch64|aa64/
'aa64'
else # ppc64, ppc64le and others
name.parameterize.gsub(/[^\w\.-]/, '_')
name.parameterize.gsub(/[^\w.-]/, '_')
end
end
end
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def normalize_vm_attrs(vm_attrs)

def url_for_fog
u = URI.parse(url)
match_data = u.path.match(%r{(.*)\/v\d+.*})
match_data = u.path.match(%r{(.*)/v\d+.*})
path = match_data && (match_data[1] || '')
"#{u.scheme}://#{u.host}:#{u.port}#{path}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Medium < ApplicationRecord
has_many :hostgroups, :dependent => :nullify

# We need to include $ in this as $arch, $release, can be in this string
VALID_NFS_PATH = /\A([-\w\d\.]+):(\/[\w\d\/\$\.]+)\Z/
VALID_NFS_PATH = /\A([-\w\d.]+):(\/[\w\d\/$.]+)\Z/
validates :name, :uniqueness => true, :presence => true
validates :path, :uniqueness => true, :presence => true,
:url_schema => ['http', 'https', 'ftp', 'nfs']
Expand Down
2 changes: 1 addition & 1 deletion app/models/operatingsystems/solaris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Solaris < Operatingsystem
PXEFILES = {:initrd => "x86.miniroot", :kernel => "multiboot"}

def file_prefix
to_s.gsub(/[\s\(\)]/, "-").gsub("--", "-").gsub(/-\Z/, "")
to_s.gsub(/[\s()]/, "-").gsub("--", "-").gsub(/-\Z/, "")
end

# sets the prefix for the tftp files based on the OS
Expand Down
2 changes: 1 addition & 1 deletion app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def parse_string_value(val)
when "array"
if val =~ /\A\[.*\]\Z/
begin
self.value = YAML.safe_load(val.gsub(/(\,)(\S)/, "\\1 \\2"))
self.value = YAML.safe_load(val.gsub(/(,)(\S)/, "\\1 \\2"))
rescue => e
invalid_value_error e.to_s
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def self.title_name
end

def self.name_format
/\A[[:alnum:]\s'_\-\.()<>;=,]*\z/
/\A[[:alnum:]\s'_\-.()<>;=,]*\z/
end

validates :login, :presence => true, :uniqueness => {:case_sensitive => false, :message => N_("already exists")},
:format => {:with => /\A[[:alnum:]_\-@\.\\$#+]*\Z/}, :length => {:maximum => 100},
:format => {:with => /\A[[:alnum:]_\-@.\\$#+]*\Z/}, :length => {:maximum => 100},
:exclusion => { in: %w(current_user) }
validates :auth_source_id, :presence => true
validates :password_hash, :presence => true, :if => proc { |user| user.manage_password? }
Expand Down
4 changes: 2 additions & 2 deletions app/services/fact_parser.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class FactParser
delegate :logger, :to => :Rails
VIRTUAL = /\A([a-z0-9]+)[_|\.|:]([a-z0-9]+)\Z/
VIRTUAL = /\A([a-z0-9]+)[_|.|:]([a-z0-9]+)\Z/
BRIDGES = /\A(vir|lxc)?br(\d+|-[a-z0-9]+)(_nic)?\Z/
BONDS = /\A(bond\d+)\Z|\A(lagg\d+)\Z/
ALIASES = /(\A[a-z0-9\.]+):([a-z0-9]+)\Z/
ALIASES = /(\A[a-z0-9.]+):([a-z0-9]+)\Z/
VLANS = /\A([a-zA-Z0-9]+)\.([0-9]+)\Z/
VIRTUAL_NAMES = /#{ALIASES}|#{VLANS}|#{VIRTUAL}|#{BRIDGES}|#{BONDS}/
# spend 500ms per IP on primary interface lookup
Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman_ansible/operating_system_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def os_release_name

def os_major
if os_name == 'Debian' &&
(facts[:ansible_distribution_major_version][%r{\/sid}i] ||
(facts[:ansible_distribution_major_version][%r{/sid}i] ||
facts[:ansible_distribution_major_version] == 'n/a')
debian_os_major_sid
else
Expand Down
2 changes: 1 addition & 1 deletion app/services/ipam/eui64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def validate

def mac_to_ip(mac)
# cleanup MAC address
mac.gsub!(/[\.\:\-]/, '')
mac.gsub!(/[.:\-]/, '')

# separate the 48-bit MAC address into two 24-bits
oui = mac.slice(0..5)
Expand Down
4 changes: 2 additions & 2 deletions app/services/puppet_fact_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def operatingsystem
if orel.present?
major, minor = orel.split('.', 2)
major = major.to_s.gsub(/\D/, '')
minor = minor.to_s.gsub(/[^\d\.]/, '')
minor = minor.to_s.gsub(/[^\d.]/, '')
args = {:name => os_name, :major => major, :minor => minor}
os = Operatingsystem.find_or_initialize_by(args)
if os_name[/debian|ubuntu/i] || os.family == 'Debian'
Expand Down Expand Up @@ -238,7 +238,7 @@ def os_release
majorjunos, minorjunos = os_release_full.split("R")
majorjunos + "." + minorjunos
when /FreeBSD/i
os_release_full.gsub(/\-RELEASE\-p[0-9]+/, '')
os_release_full.gsub(/-RELEASE-p[0-9]+/, '')
when /Solaris/i
os_release_full.gsub(/_u/, '.')
when /PSBM/i
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/puppet.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace :puppet do
name = yaml.match(/.*\/(.*).yaml/)[1]
puts "Importing #{name}"
puppet_facts = File.read(yaml)
facts_stripped_of_class_names = YAML.safe_load(puppet_facts.gsub(/\!ruby\/object.*$/, ''))
facts_stripped_of_class_names = YAML.safe_load(puppet_facts.gsub(/!ruby\/object.*$/, ''))
User.as_anonymous_admin do
host = Host::Managed.import_host(facts_stripped_of_class_names['name'], 'puppet')
HostFactImporter.new(host).import_facts(facts_stripped_of_class_names['values'])
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/registration_commands_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,29 @@ class RegistrationCommandsControllerTest < ActionController::TestCase
test 'with default expiration' do
post :create, session: set_session_user
command = JSON.parse(@response.body)['command']
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=\')/).flatten[0]
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=')/).flatten[0]
assert JwtToken.new(parsed_token).decode['exp']
end

test 'with expiration' do
post :create, params: { jwt_expiration: 23 }, session: set_session_user
command = JSON.parse(@response.body)['command']
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=\')/).flatten[0]
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=')/).flatten[0]
assert JwtToken.new(parsed_token).decode['exp']
end

test 'unlimited' do
post :create, params: { jwt_expiration: 'unlimited' }, session: set_session_user
command = JSON.parse(@response.body)['command']
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=\')/).flatten[0]
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=')/).flatten[0]

refute JwtToken.new(parsed_token).decode['exp']
end

test '0' do
post :create, params: { jwt_expiration: 0 }, session: set_session_user
command = JSON.parse(@response.body)['command']
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=\')/).flatten[0]
parsed_token = command.scan(/(?<=Bearer )(.*)(?=.*)(?=')/).flatten[0]
refute JwtToken.new(parsed_token).decode['exp']
end

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class FormHelperTest < ActionView::TestCase
user = FactoryBot.build_stubbed(:user,
:organizations => [taxonomies(:organization1)])
form_for Filter.new do |f|
assert_match(/input name=\"filter\[organization_ids\]\[\].*/,
assert_match(/input name="filter\[organization_ids\]\[\].*/,
multiple_checkboxes(f, :organizations, f.object, user.organizations))
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/concerns/hostext/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class SearchTest < ActiveSupport::TestCase
end

test "invalid fact property should properly format" do
assert_match /\'goofy.bad\'/, Host.search_for("facts.goofy.bad=value").to_sql
assert_match /\'goofy\'/, Host.search_for("facts.goofy=value").to_sql
assert_match /'goofy.bad'/, Host.search_for("facts.goofy.bad=value").to_sql
assert_match /'goofy'/, Host.search_for("facts.goofy=value").to_sql
end

test "searching fact on complex search returns correct host" do
Expand Down

0 comments on commit 6656415

Please sign in to comment.