diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-05 11:44:16 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-05 12:41:14 -0700 |
commit | 7bf98ad06b30b7feb4ea3fbbe45a5b733467a5d3 (patch) | |
tree | b0995ded1a63654d3f54140bd880c69f86afd52f /lib | |
parent | 9802d7c075c8b7dae42dbcecd92d492f7fa128ac (diff) | |
download | chef-7bf98ad06b30b7feb4ea3fbbe45a5b733467a5d3.tar.gz |
Style/RegexpLiteral
given how many regexps we have with /'s in the match this seems like
a very good one.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
35 files changed, 50 insertions, 50 deletions
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index 0da696c05c..29ba1971e1 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -272,7 +272,7 @@ class Chef::Application::Solo < Chef::Application Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval] if Chef::Config[:recipe_url] - cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| Pathname.new(e).cleanpath.to_s =~ /\/cookbooks\/*$/ } + cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| Pathname.new(e).cleanpath.to_s =~ %r{/cookbooks/*$} } recipes_path = File.expand_path(File.join(cookbooks_path, "..")) if Chef::Config[:delete_entire_chef_repo] diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index e0df23371c..8a942103f1 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -307,7 +307,7 @@ class Chef begin case config[:config_file] - when /^(http|https):\/\// + when %r{^(http|https)://} Chef::HTTP.new("").streaming_request(config[:config_file]) { |f| apply_config(f.path) } else ::File.open(config[:config_file]) { |f| apply_config(f.path) } diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb index 48ebe75e27..83e82bfa0c 100644 --- a/lib/chef/chef_fs/config.rb +++ b/lib/chef/chef_fs/config.rb @@ -164,7 +164,7 @@ class Chef attr_reader :cookbook_version def is_hosted? - @chef_config[:chef_server_url] =~ /\/+organizations\/.+/ + @chef_config[:chef_server_url] =~ %r{/+organizations/.+} end def chef_fs diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 6d1b3e1f61..0b62718ab9 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -52,7 +52,7 @@ class Chef @inferred_cookbook_name = File.basename( path ) @chefignore = chefignore @metadata = nil - @relative_path = /#{Regexp.escape(cookbook_path)}\/(.+)$/ + @relative_path = %r{#{Regexp.escape(cookbook_path)}/(.+)$} @metadata_loaded = false @cookbook_settings = { all_files: {}, diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index ebdb94ee54..e5270018fb 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -37,7 +37,7 @@ class Chef # Chef::Config.cookbook_path file hierarchy for the requested # file. def get_filename(filename) - if filename =~ /([^\/]+)\/(.+)$/ + if filename =~ %r{([^/]+)/(.+)$} segment = $1 else raise "get_filename: Cannot determine segment/filename for incoming filename #{filename}" diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index b69e6b8212..342fc89f16 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -209,7 +209,7 @@ class Chef # (if we have an override run_list we may not want to do this) def remove_old_cookbooks cache.find(File.join(%w{cookbooks ** {*,.*}})).each do |cache_file| - cache_file =~ /^cookbooks\/([^\/]+)\// + cache_file =~ %r{^cookbooks/([^/]+)/} unless have_cookbook?($1) Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.") cache.delete(cache_file) @@ -221,7 +221,7 @@ class Chef # remove deleted files in cookbooks that are being used on the node def remove_deleted_files cache.find(File.join(%w{cookbooks ** {*,.*}})).each do |cache_file| - md = cache_file.match(/^cookbooks\/([^\/]+)\/([^\/]+)\/(.*)/) + md = cache_file.match(%r{^cookbooks/([^/]+)/([^/]+)/(.*)}) next unless md ( cookbook_name, segment, file ) = md[1..3] diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 959318a020..d546724fa0 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -296,9 +296,9 @@ class Chef # we're just going to make cookbook_files out of these and make the # cookbook find them by filespecificity again. but it's the shortest # path to "success" for now. - if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)})\/.+$/ + if manifest_record_path =~ %r{(#{Regexp.escape(segment.to_s)}/[^/]*/?#{Regexp.escape(dirname)})/.+$} specificity_dirname = $1 - non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)}\/(.+)$/, 1] + non_specific_path = manifest_record_path[%r{#{Regexp.escape(segment.to_s)}/[^/]*/?#{Regexp.escape(dirname)}/(.+)$}, 1] # Record the specificity_dirname only if it's in the list of # valid preferences if filenames_by_pref[specificity_dirname] @@ -326,7 +326,7 @@ class Chef manifest_record_path = manifest_record[:path] # extract the preference part from the path. - if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/ + if manifest_record_path =~ %r{(#{Regexp.escape(segment.to_s)}/[^/]+/#{Regexp.escape(dirname)})/.+$} # Note the specificy_dirname includes the segment and # dirname argument as above, which is what # preferences_for_path returns. It could be diff --git a/lib/chef/encrypted_data_bag_item.rb b/lib/chef/encrypted_data_bag_item.rb index e8a979f7c0..d1928d195b 100644 --- a/lib/chef/encrypted_data_bag_item.rb +++ b/lib/chef/encrypted_data_bag_item.rb @@ -135,7 +135,7 @@ class Chef::EncryptedDataBagItem end secret = case path - when /^\w+:\/\// + when %r{^\w+://} # We have a remote key begin Kernel.open(path).read.strip diff --git a/lib/chef/http.rb b/lib/chef/http.rb index b5f6a91c5d..3cee587fd5 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -312,7 +312,7 @@ class Chef def create_url(path) return path if path.is_a?(URI) - if path =~ /^(http|https|chefzero):\/\//i + if path =~ %r{^(http|https|chefzero)://}i URI.parse(path) elsif path.nil? || path.empty? URI.parse(@url) diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 4be53af5c8..e892f1f2c9 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -663,7 +663,7 @@ class Chef def connection_protocol return @connection_protocol if @connection_protocol - from_url = host_descriptor =~ /^(.*):\/\// ? $1 : nil + from_url = host_descriptor =~ %r{^(.*)://} ? $1 : nil from_cli = config[:connection_protocol] from_knife = Chef::Config[:knife][:connection_protocol] @connection_protocol = from_url || from_cli || from_knife || "ssh" diff --git a/lib/chef/mixin/convert_to_class_name.rb b/lib/chef/mixin/convert_to_class_name.rb index a65fa87655..c5944c3985 100644 --- a/lib/chef/mixin/convert_to_class_name.rb +++ b/lib/chef/mixin/convert_to_class_name.rb @@ -25,7 +25,7 @@ class Chef def convert_to_class_name(str) str = normalize_snake_case_name(str) rname = nil - regexp = %r{^(.+?)(_(.+))?$} + regexp = /^(.+?)(_(.+))?$/ mn = str.match(regexp) if mn diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index ec810739ab..aad59d1eba 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -29,7 +29,7 @@ class Chef CRON_ATTRIBUTES = %i{minute hour day month weekday time command mailto path shell home environment}.freeze WEEKDAY_SYMBOLS = %i{sunday monday tuesday wednesday thursday friday saturday}.freeze - CRON_PATTERN = /\A([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+|[a-zA-Z]{3})\s([-0-9*,\/]+|[a-zA-Z]{3})\s(.*)/.freeze + CRON_PATTERN = %r{\A([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+|[a-zA-Z]{3})\s([-0-9*,/]+|[a-zA-Z]{3})\s(.*)}.freeze SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join('|')}))\s(.*)/.freeze ENV_PATTERN = /\A(\S+)=(\S*)/.freeze ENVIRONMENT_PROPERTIES = %w{MAILTO PATH SHELL HOME}.freeze diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index 3dd574c401..16d1e54408 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -51,7 +51,7 @@ class Chef end requirements.assert(:all_actions) do |a| - a.assertion { !(new_resource.revision =~ /^origin\//) } + a.assertion { !(new_resource.revision =~ %r{^origin/}) } a.failure_message Chef::Exceptions::InvalidRemoteGitReference, "Deploying remote branches is not supported. " + "Specify the remote branch as a local branch for " + diff --git a/lib/chef/provider/mount/aix.rb b/lib/chef/provider/mount/aix.rb index ca6ca4bd63..0a5e30447b 100644 --- a/lib/chef/provider/mount/aix.rb +++ b/lib/chef/provider/mount/aix.rb @@ -110,7 +110,7 @@ class Chef when /#{search_device}\s+#{Regexp.escape(@new_resource.mount_point)}/ mounted = true logger.trace("Special device #{device_logstring} mounted as #{@new_resource.mount_point}") - when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ + when %r{^[/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+} mounted = false logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end @@ -196,7 +196,7 @@ class Chef found_device = false ::File.open("/etc/filesystems", "r").each_line do |line| case line - when /^\/.+:\s*$/ + when %r{^/.+:\s*$} if line =~ /#{Regexp.escape(@new_resource.mount_point)}+:/ found_device = true else diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index fe9a6ffc4f..4fdcc257da 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -71,7 +71,7 @@ class Chef @current_resource.pass($5.to_i) logger.trace("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab") next - when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ + when %r{^[/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+} enabled = false logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end @@ -96,7 +96,7 @@ class Chef when /^#{device_mount_regex}\s+on\s+#{Regexp.escape(real_mount_point)}\s/ mounted = true logger.trace("Special device #{device_logstring} mounted as #{real_mount_point}") - when /^([\/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+/ + when %r{^([/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+} mounted = false logger.trace("Special device #{$~[1]} mounted as #{real_mount_point}") end @@ -201,7 +201,7 @@ class Chef end def network_device? - @new_resource.device =~ /:/ || @new_resource.device =~ /\/\// + @new_resource.device =~ /:/ || @new_resource.device =~ %r{//} end def device_should_exist? diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb index 69659d4918..ae26d13117 100644 --- a/lib/chef/provider/mount/solaris.rb +++ b/lib/chef/provider/mount/solaris.rb @@ -158,7 +158,7 @@ class Chef when /^#{device_regex}\s+on\s+#{Regexp.escape(mount_point)}\s+/ logger.trace("Special device #{device} is mounted as #{mount_point}") mounted = true - when /^([\/\w]+)\son\s#{Regexp.escape(mount_point)}\s+/ + when %r{^([/\w]+)\son\s#{Regexp.escape(mount_point)}\s+} logger.trace("Special device #{Regexp.last_match[1]} is mounted as #{mount_point}") mounted = false end @@ -180,7 +180,7 @@ class Chef # solaris /etc/vfstab format: # device device mount FS fsck mount mount # to mount to fsck point type pass at boot options - when /^#{device_regex}\s+[-\/\w]+\s+#{Regexp.escape(mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ + when %r{^#{device_regex}\s+[-/\w]+\s+#{Regexp.escape(mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)} enabled = true fstype = Regexp.last_match[1] options = Regexp.last_match[4] @@ -196,7 +196,7 @@ class Chef pass = (Regexp.last_match[2] == "-") ? 0 : Regexp.last_match[2].to_i logger.trace("Found mount #{device} to #{mount_point} in #{VFSTAB}") next - when /^[-\/\w]+\s+[-\/\w]+\s+#{Regexp.escape(mount_point)}\s+/ + when %r{^[-/\w]+\s+[-/\w]+\s+#{Regexp.escape(mount_point)}\s+} # if we find a mountpoint on top of our mountpoint, then we are not enabled enabled = false logger.trace("Found conflicting mount point #{mount_point} in #{VFSTAB}") diff --git a/lib/chef/provider/package/freebsd/base.rb b/lib/chef/provider/package/freebsd/base.rb index bfd828552c..70ca3f4a98 100644 --- a/lib/chef/provider/package/freebsd/base.rb +++ b/lib/chef/provider/package/freebsd/base.rb @@ -37,12 +37,12 @@ class Chef case port # When the package name starts with a '/' treat it as the full path to the ports directory. - when /^\// + when %r{^/} port # Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat # as a relative path from /usr/ports. - when /\// + when %r{/} "/usr/ports/#{port}" # Otherwise look up the path to the ports directory using 'whereis' diff --git a/lib/chef/provider/package/freebsd/pkgng.rb b/lib/chef/provider/package/freebsd/pkgng.rb index a3d70ad9cd..fb79af617f 100644 --- a/lib/chef/provider/package/freebsd/pkgng.rb +++ b/lib/chef/provider/package/freebsd/pkgng.rb @@ -27,7 +27,7 @@ class Chef def install_package(name, version) unless current_resource.version case new_resource.source - when /^(http|ftp|\/)/ + when %r{^(http|ftp|/)} shell_out!("pkg", "add", options, new_resource.source, env: { "LC_ALL" => nil }).status logger.trace("#{new_resource} installed from: #{new_resource.source}") else diff --git a/lib/chef/provider/package/snap.rb b/lib/chef/provider/package/snap.rb index c9f9e1134f..cb639ff77f 100644 --- a/lib/chef/provider/package/snap.rb +++ b/lib/chef/provider/package/snap.rb @@ -190,7 +190,7 @@ class Chef def get_snap_version_from_source(path) body = { "context-id" => "get_snap_version_from_source_#{path}", - "args" => ["info", path,], + "args" => ["info", path], }.to_json # json = call_snap_api('POST', '/v2/snapctl', body) diff --git a/lib/chef/provider/package/windows/msi.rb b/lib/chef/provider/package/windows/msi.rb index a6807afc17..91b3d7a2b2 100644 --- a/lib/chef/provider/package/windows/msi.rb +++ b/lib/chef/provider/package/windows/msi.rb @@ -84,7 +84,7 @@ class Chef .map(&:uninstall_string).uniq.each do |uninstall_string| uninstall_string = "msiexec /x #{uninstall_string.match(/{.*}/)}" uninstall_string += expand_options(new_resource.options) - uninstall_string += " /q" unless uninstall_string.downcase =~ / \/q/ + uninstall_string += " /q" unless uninstall_string.downcase =~ %r{ /q} logger.trace("#{new_resource} removing MSI package version using '#{uninstall_string}'") shell_out!(uninstall_string, timeout: new_resource.timeout, returns: new_resource.returns) end diff --git a/lib/chef/provider/remote_file/fetcher.rb b/lib/chef/provider/remote_file/fetcher.rb index 85318b1df7..f007fe40db 100644 --- a/lib/chef/provider/remote_file/fetcher.rb +++ b/lib/chef/provider/remote_file/fetcher.rb @@ -49,7 +49,7 @@ class Chef def self.network_share?(source) case source when String - !!(%r{\A\\\\[A-Za-z0-9+\-\.]+} =~ source) + !!(/\A\\\\[A-Za-z0-9+\-\.]+/ =~ source) else false end diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index 14877806ce..d4b71e24fa 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -35,7 +35,7 @@ class Chef # CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI def fix_windows_path(path) - path.gsub(/^\/([a-zA-Z]:)/, '\1') + path.gsub(%r{^/([a-zA-Z]:)}, '\1') end def source_path diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index 6469b6389c..05cdc2befe 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -22,7 +22,7 @@ class Chef class Provider class Service class AixInit < Chef::Provider::Service::Init - RC_D_SCRIPT_NAME = /\/etc\/rc.d\/rc2.d\/([SK])(\d\d|)/i.freeze + RC_D_SCRIPT_NAME = %r{/etc/rc.d/rc2.d/([SK])(\d\d|)}i.freeze def initialize(new_resource, run_context) super diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index de76ed1416..9f48504d5e 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -26,8 +26,8 @@ class Chef Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian) end - UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i.freeze - UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i.freeze + UPDATE_RC_D_ENABLED_MATCHES = %r{/rc[\dS].d/S|not installed}i.freeze + UPDATE_RC_D_PRIORITIES = %r{/rc([\dS]).d/([SK])(\d\d)}i.freeze def self.supports?(resource, action) Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 5364053ba8..8b2db84f35 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -32,7 +32,7 @@ class Chef Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) end - UPSTART_STATE_FORMAT = /\S+ \(?(start|stop)?\)? ?[\/ ](\w+)/.freeze + UPSTART_STATE_FORMAT = %r{\S+ \(?(start|stop)?\)? ?[/ ](\w+)}.freeze # Returns true if the configs for the service name has upstart variable def self.supports?(resource, action) diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index e1bdabce42..79ac2b1e29 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -307,7 +307,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service # remove characters that make for broken or wonky filenames. def clean_username_for_path(username) - username.gsub(/[\/\\. ]+/, "_") + username.gsub(%r{[/\\. ]+}, "_") end def canonicalize_username(username) diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 147de19a65..e67aec974a 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -291,7 +291,7 @@ in 'password', with the associated 'salt' and 'iterations'.") end def validate_home_dir_specification! - unless new_resource.home =~ /^\// + unless new_resource.home =~ %r{^/} raise(Chef::Exceptions::InvalidHomeDirectory, "invalid path spec for User: '#{new_resource.username}', home directory: '#{new_resource.home}'") end end diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb index 291a545843..764979cb3a 100644 --- a/lib/chef/provider/zypper_repository.rb +++ b/lib/chef/provider/zypper_repository.rb @@ -134,7 +134,7 @@ class Chef def key_fingerprint(key_path) so = shell_out!("gpg --with-fingerprint #{key_path}") # expected output and match: http://rubular.com/r/BpfMjxySQM - fingerprint = /pub\s*\S*\/(\S*)/.match(so.stdout)[1].downcase + fingerprint = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}") fingerprint end diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index c70631253b..c73408807d 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -33,7 +33,7 @@ class Chef # defaults, but since we allowed users to pass nil here we need to continue # to allow that so don't refactor this however tempting it is property :repo_name, String, - regex: [/^[^\/]+$/], + regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name. The value of this setting must not contain spaces.", validation_message: "repo_name property cannot contain a forward slash '/'", introduced: "14.1", name_property: true diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb index 71160e983e..dab599c272 100644 --- a/lib/chef/resource/hostname.rb +++ b/lib/chef/resource/hostname.rb @@ -203,7 +203,7 @@ class Chef declare_resource(:execute, "svccfg -s system/identity:node setprop config/nodename=\'#{new_resource.hostname}\'") do notifies :run, "execute[svcadm refresh]", :immediately notifies :run, "execute[svcadm restart]", :immediately - not_if { shell_out!("svccfg -s system/identity:node listprop config/nodename").stdout.chomp =~ /config\/nodename\s+astring\s+#{new_resource.hostname}/ } + not_if { shell_out!("svccfg -s system/identity:node listprop config/nodename").stdout.chomp =~ %r{config/nodename\s+astring\s+#{new_resource.hostname}} } end declare_resource(:execute, "svcadm refresh") do command "svcadm refresh system/identity:node" diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 0ce5bf2031..6220400069 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -31,7 +31,7 @@ class Chef allowed_actions :create, :delete, :run, :end, :enable, :disable, :change default_action :create - property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/], + property :task_name, String, regex: [%r{\A[^/\:\*\?\<\>\|]+\z}], description: "An optional property to set the task name if it differs from the resource block's name. Example: 'Task Name' or '/Task Name'", name_property: true @@ -216,7 +216,7 @@ class Chef # make sure the start_day is in MM/DD/YYYY format: http://rubular.com/r/cgjHemtWl5 if start_day - raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/ =~ start_day + raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless %r{^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$} =~ start_day end end diff --git a/lib/chef/resource/yum_repository.rb b/lib/chef/resource/yum_repository.rb index 1883439da1..05639842af 100644 --- a/lib/chef/resource/yum_repository.rb +++ b/lib/chef/resource/yum_repository.rb @@ -142,7 +142,7 @@ class Chef property :report_instanceid, [TrueClass, FalseClass], description: "Determines whether to report the instance ID when using Amazon Linux AMIs and repositories." - property :repositoryid, String, regex: [/^[^\/]+$/], + property :repositoryid, String, regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name.", validation_message: "repositoryid property cannot contain a forward slash '/'", name_property: true diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb index 92ab012c66..447660e9ac 100644 --- a/lib/chef/resource/zypper_repository.rb +++ b/lib/chef/resource/zypper_repository.rb @@ -29,7 +29,7 @@ class Chef introduced "13.3" property :repo_name, String, - regex: [/^[^\/]+$/], + regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name.", validation_message: "repo_name property cannot contain a forward slash '/'", name_property: true diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 034e9484a4..8607833a55 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -249,8 +249,8 @@ class Chef paths = Array(Chef::Config[:role_path]) paths.each do |path| roles_files = Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "**")) - js_files = roles_files.select { |file| file.match(/\/#{name}\.json$/) } - rb_files = roles_files.select { |file| file.match(/\/#{name}\.rb$/) } + js_files = roles_files.select { |file| file.match(%r{/#{name}\.json$}) } + rb_files = roles_files.select { |file| file.match(%r{/#{name}\.rb$}) } if js_files.count > 1 || rb_files.count > 1 raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}" end diff --git a/lib/chef/run_list/run_list_item.rb b/lib/chef/run_list/run_list_item.rb index f5aec6de5e..e9e4f85ce3 100644 --- a/lib/chef/run_list/run_list_item.rb +++ b/lib/chef/run_list/run_list_item.rb @@ -18,10 +18,10 @@ class Chef class RunList class RunListItem - QUALIFIED_RECIPE = %r{^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$}.freeze - QUALIFIED_ROLE = %r{^role\[([^\]]+)\]$}.freeze - VERSIONED_UNQUALIFIED_RECIPE = %r{^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$}.freeze - FALSE_FRIEND = %r{[\[\]]}.freeze + QUALIFIED_RECIPE = /^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$/.freeze + QUALIFIED_ROLE = /^role\[([^\]]+)\]$/.freeze + VERSIONED_UNQUALIFIED_RECIPE = /^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$/.freeze + FALSE_FRIEND = /[\[\]]/.freeze attr_reader :name, :type, :version |