Skip to content

Commit

Permalink
Remove obsolete gem SafeYAML compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Nov 7, 2020
1 parent 3e349e3 commit 64e9b8c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 52 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ gem 'test-queue'
gem 'yard', '~> 0.9'

group :test do
gem 'safe_yaml', require: false
gem 'webmock', require: false
end

Expand Down
1 change: 1 addition & 0 deletions changelog/change_remove_obsolete_gem_safeyaml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9004](https://github.com/rubocop-hq/rubocop/pull/9004): Remove obsolete gem `SafeYAML` compatibility. ([@marcandre][])
13 changes: 7 additions & 6 deletions lib/rubocop/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,18 @@ def read_file(absolute_path)
"Configuration file not found: #{absolute_path}"
end

def yaml_safe_load(yaml_code, filename)
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
# Ruby 2.6+
elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
raise 'SafeYAML is unmaintained, no longer needed and should be removed' if defined?(SafeYAML)

if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
def yaml_safe_load(yaml_code, filename)
YAML.safe_load(yaml_code,
permitted_classes: [Regexp, Symbol],
permitted_symbols: [],
aliases: true,
filename: filename)
else
end
else # Ruby < 2.6
def yaml_safe_load(yaml_code, filename)
YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
end
end
Expand Down
45 changes: 0 additions & 45 deletions spec/rubocop/config_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1307,51 +1307,6 @@ def cop_enabled?(cop_class)
expect(configuration.to_h).to eq({})
end

context 'when SafeYAML is required' do
before do
create_file(configuration_path, <<~YAML)
Style/WordArray:
WordRegex: !ruby/regexp '/\\A[\\p{Word}]+\\z/'
YAML
end

context 'when it is fully required', broken_on: :ruby_head do
it 'de-serializes Regexp class' do
in_its_own_process_with('safe_yaml') do
configuration = described_class.load_file('.rubocop.yml')

word_regexp = configuration['Style/WordArray']['WordRegex']
expect(word_regexp.is_a?(::Regexp)).to be(true)
end
end
end

context 'when safe_yaml is required without monkey patching', broken_on: :ruby_head do
it 'de-serializes Regexp class' do
in_its_own_process_with('safe_yaml/load') do
configuration = described_class.load_file('.rubocop.yml')

word_regexp = configuration['Style/WordArray']['WordRegex']
expect(word_regexp.is_a?(::Regexp)).to be(true)
end
end

context 'and SafeYAML.load is private' do
# According to issue #2935, SafeYAML.load can be private in some
# circumstances.
it 'does not raise private method load called for SafeYAML:Module' do
in_its_own_process_with('safe_yaml/load') do
SafeYAML.public_send :private_class_method, :load
configuration = described_class.load_file('.rubocop.yml')

word_regexp = configuration['Style/WordArray']['WordRegex']
expect(word_regexp.is_a?(::Regexp)).to be(true)
end
end
end
end
end

context 'set neither true nor false to value to Enabled' do
before do
create_file(configuration_path, <<~YAML)
Expand Down

0 comments on commit 64e9b8c

Please sign in to comment.