Skip to content

Commit 0f7dbf7

Browse files
committed
Replacing URI.escape with URI::DEFAULT_PARSER
URI.escape was deprecated in ruby-2.7 and removed in ruby-3.x. This change is breaking stdlib. Replacing URI.escape with URI::DEFAULT_PARSER is working properly.
1 parent f1acb05 commit 0f7dbf7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/puppet/parser/functions/uriescape.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ module Puppet::Parser::Functions
2626

2727
result = if value.is_a?(Array)
2828
# Numbers in Puppet are often string-encoded which is troublesome ...
29-
value.map { |i| i.is_a?(String) ? URI.escape(i) : i }
29+
value.map { |i| i.is_a?(String) ? URI::DEFAULT_PARSER.escape(i) : i }
3030
else
31-
URI.escape(value)
31+
URI::DEFAULT_PARSER.escape(value)
3232
end
3333

3434
return result

spec/functions/uriescape_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
end
1717

1818
describe 'handling normal strings' do
19-
it 'calls ruby\'s URI.escape function' do
19+
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
2020
expect(URI).to receive(:escape).with('uri_string').and_return('escaped_uri_string').once
2121
is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
2222
end
2323
end
2424

2525
describe 'handling classes derived from String' do
26-
it 'calls ruby\'s URI.escape function' do
26+
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
2727
uri_string = AlsoString.new('uri_string')
2828
expect(URI).to receive(:escape).with(uri_string).and_return('escaped_uri_string').once
2929
is_expected.to run.with_params(uri_string).and_return('escaped_uri_string')

0 commit comments

Comments
 (0)