Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Ruby 3.1 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ gem "rake", :require => false
gemspec

group :test do
gem "safe_yaml", :require => false
gem "luna-rspec-formatters", :require => false
gem "simplecov", :require => false
end
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ but only if they originate from the given root.
- `>=`, `>` - Check if a file is in but ahead of a path: `Pathutil.new("/tmp/hello") > "/tmp" # => true`
- `in_path?` - Check if a file is within a given path: `Pathutil.new("/tmp/hello").in_path?("/tmp") # => true`
- `<=`, `<` - Check if a file is in but below a path: `Pathutil.new("/tmp") < "/tmp/hello" # => true`
- `read_yaml` - a wrapper around `Yaml.safe_load` and `SafeYAML` to make reading `YAML` easy.
- `read_yaml` - a wrapper around `Yaml.safe_load` to make reading `YAML` easy.
- `children` - behaves like Pathname, except it accepts a block to work on the path.
- `safe_copy` - Copy files, disallowing symlinks unless `in_path?`
- `enforce_root` - Force a root if not already in that root.
Expand Down
16 changes: 0 additions & 16 deletions benchmark/yaml.rb

This file was deleted.

38 changes: 7 additions & 31 deletions lib/pathutil/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def allowed
end

# --
# Wraps around YAML and SafeYAML to provide alternatives to Rubies.
# Wraps around YAMLto provide alternatives to Rubies.
# @note We default aliases to yes so we can detect if you explicit true.
# @return Hash
# --
Expand All @@ -34,20 +34,12 @@ def load_yaml(data, safe: true, whitelist_classes: allowed[:yaml][:classes], \
)
end

if !YAML.respond_to?(:safe_load)
setup_safe_yaml whitelist_classes, aliases
SafeYAML.load(
data
)

else
YAML.safe_load(
data,
whitelist_classes,
whitelist_symbols,
aliases
)
end
YAML.safe_load(
data,
permitted_classes: whitelist_classes,
permitted_symbols: whitelist_symbols,
aliases: aliases
)
end

# --
Expand Down Expand Up @@ -109,21 +101,5 @@ def tmpname_prefix(prefix)
prefix, ext || ""
]
end

# --
# Wrap around, cleanup, deprecate and use SafeYAML.
# rubocop:enable Style/ParallelAssignment
# --
private
def setup_safe_yaml(whitelist_classes, aliases)
warn "WARN: SafeYAML does not support disabling of aliases." if aliases && aliases != :yes
warn "WARN: SafeYAML will be removed when Ruby 2.0 goes EOL."
require "safe_yaml/load"

SafeYAML.restore_defaults!
whitelist_classes.map(&SafeYAML.method(
:whitelist_class!
))
end
end
end
55 changes: 0 additions & 55 deletions spec/tests/lib/pathutil/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,6 @@
Psych::DisallowedClass
)
end

#

context "when using SafeYAML" do
before do
allow(YAML).to receive(:respond_to?).with(:safe_load).and_return(false)
expect_any_instance_of(described_class).to receive(:warn).and_return(
nil
)
end

#

context do
it "should warn it's deprecated" do
expect(described_class).to receive(:warn).and_return(
nil
)
end

#

after do
described_class.load_yaml(
":hello: :world"
)
end
end

#

context "when trying to disable aliases" do
it "should warn that you cannot disable them in SafeYAML" do
expect(described_class).to receive(:warn).exactly(2).times.and_return(
nil
)
end

#

after do
described_class.load_yaml("hello: world", {
:aliases => true
})
end
end

#

it "should parse with SafeYAML" do
expect(described_class.load_yaml(":hello: :world")).to eq({
":hello" => ":world"
})
end
end
end

#
Expand Down