Skip to content

Commit

Permalink
Replacing URI.escape with URI::DEFAULT_PARSER
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valleedelisle committed Jul 27, 2021
1 parent f1acb05 commit a60df53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/uriescape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ module Puppet::Parser::Functions

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

return result
Expand Down
8 changes: 4 additions & 4 deletions spec/functions/uriescape_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
end

describe 'handling normal strings' do
it 'calls ruby\'s URI.escape function' do
expect(URI).to receive(:escape).with('uri_string').and_return('escaped_uri_string').once
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
expect(URI::DEFAULT_PARSER).to receive(:escape).with('uri_string').and_return('escaped_uri_string').once
is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
end
end

describe 'handling classes derived from String' do
it 'calls ruby\'s URI.escape function' do
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
uri_string = AlsoString.new('uri_string')
expect(URI).to receive(:escape).with(uri_string).and_return('escaped_uri_string').once
expect(URI::DEFAULT_PARSER).to receive(:escape).with(uri_string).and_return('escaped_uri_string').once
is_expected.to run.with_params(uri_string).and_return('escaped_uri_string')
end
end
Expand Down

0 comments on commit a60df53

Please sign in to comment.