1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
https://github.com/envygeeks/pathutil/pull/7
From c0ecc9a516ed43facfb3a80735034c892d517d1a Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sun, 3 Apr 2022 20:20:44 +0200
Subject: [PATCH 1/2] Fix usage of YAML.safe_load for compatibility with Ruby
>=2.4
YAML.safe_load in Ruby 3.1.1 doesn't accept deprecated positional parameters anymore:
1) Pathutil::Helpers#load_yaml should be able to parse YAML
Failure/Error:
YAML.safe_load(
data,
whitelist_classes,
whitelist_symbols,
aliases
)
ArgumentError:
wrong number of arguments (given 4, expected 1)
# ./lib/pathutil/helpers.rb:44:in `load_yaml'
# ./spec/tests/lib/pathutil/helpers_spec.rb:25:in `block (3 levels) in <top (required)>'
From 868efe4022f944cef81b05ae01e00fab2d51ee5c Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sun, 3 Apr 2022 20:35:50 +0200
Subject: [PATCH 2/2] Remove deprecated SafeYAML support
SafeYAML has been deprecated a very long time ago.
--- a/Gemfile
+++ b/Gemfile
@@ -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
--- a/README.md
+++ b/README.md
@@ -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.
--- a/benchmark/yaml.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# Frozen-string-literal: true
-# Copyright: 2015 - 2017 Jordon Bedwell - MIT License
-# Encoding: utf-8
-
-require "bundler/setup"
-require "safe_yaml/load"
-require "benchmark/ips"
-require "pathutil"
-
-data = "hello: world\nworld: hello"
-Benchmark.ips :quiet => true do |x|
- x.json! "benchmark.json"
- x.report("A:SafeYAML.load") { SafeYAML.load(data) }
- x.report("B:Pathutil::Helpers.load_yaml") { Pathutil::Helpers.load_yaml(data) }
- x.compare!
-end
--- a/lib/pathutil/helpers.rb
+++ b/lib/pathutil/helpers.rb
@@ -20,7 +20,7 @@ class Pathutil
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
# --
@@ -34,20 +34,12 @@ class Pathutil
)
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
# --
@@ -109,21 +101,5 @@ class Pathutil
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
--- a/spec/tests/lib/pathutil/helpers_spec.rb
+++ b/spec/tests/lib/pathutil/helpers_spec.rb
@@ -26,113 +26,10 @@ describe Pathutil::Helpers do
"hello" => "world"
})
end
+ end
#
- context "when safe" do
- it "should reject any special classes", :disable => :oldest_ruby do
- expect { described_class.load_yaml(":hello: :world") }.to raise_error(
- 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
-
- #
-
- context "when whitelisting classes" do
- it "should allow that class to be loaded" do
- expect(described_class.load_yaml(":hello: :world", :whitelist_classes => [Symbol])).to eq({
- :hello => :world
- })
- end
- end
-
- #
-
- context "when diallowing aliases" do
- it "should throw the parse" do
- yaml = "version: &version 1\nother_version: *version"
- expect { described_class.load_yaml(yaml, :aliases => false) }.to raise_error(
- Psych::BadAlias
- )
- end
- end
-
- #
-
- context do
- it "should allow aliases by default" do
- expect(described_class.load_yaml("version: &version 1\nother_version: *version")).to eq({
- "version" => 1, "other_version" => 1
- })
- end
- end
-
- #
-
- context do
- it "should parse YAML" do
- expect(described_class.load_yaml("hello: world\nworld: hello")).to eq({
- "hello" => "world",
- "world" => "hello"
- })
- end
- end
- end
-
#
describe ".make_tmpname" do
|