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

Support Psych version 4 #1338

Merged
merged 1 commit into from
Sep 15, 2021
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).

### Fixed

- None
- [#1338](https://github.com/paper-trail-gem/paper_trail/pull/1338) -
Support Psych version 4

## 12.1.0 (2021-08-30)

Expand Down
2 changes: 1 addition & 1 deletion lib/paper_trail/serializers/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module YAML
extend self # makes all instance methods become module methods as well

def load(string)
::YAML.load string
::YAML.respond_to?(:unsafe_load) ? ::YAML.unsafe_load(string) : ::YAML.load(string)
end

# @param object (Hash | HashWithIndifferentAccess) - Coming from
Expand Down
13 changes: 13 additions & 0 deletions spec/paper_trail/serializers/yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ module Serializers
expect(described_class.load(hash.to_yaml)).to eq(hash)
expect(described_class.load(array.to_yaml)).to eq(array)
end

it "calls the expected load method based on Psych version" do
# Psych 4+ implements .unsafe_load
if ::YAML.respond_to?(:unsafe_load)
allow(::YAML).to receive(:unsafe_load)
described_class.load("string")
expect(::YAML).to have_received(:unsafe_load)
else # Psych < 4
allow(::YAML).to receive(:load)
described_class.load("string")
expect(::YAML).to have_received(:load)
end
end
end

describe ".dump" do
Expand Down