puppet-nova/lib/puppet/functions/encode_url_queries_for_python.rb
Takashi Kajinami 2dcad6d8dc Replace usage of uriescape
The uriescape function from puppetlabs-stdlib is no longer functional
in Puppet 8, because the URI.escape, which is internally used by that
function, is no longer available in Ruby 3+.

This replaces the function by own function to avoid the failure in
Puppet 8.

Closes-Bug: #2057860
Change-Id: I7b4db4c1e64416e20d8470cbff0b8497c6a0cfc9
2024-03-15 23:05:08 +09:00

20 lines
545 B
Ruby

Puppet::Functions.create_function(:encode_url_queries_for_python) do
def encode_url_queries_for_python(*args)
require 'uri'
if (args.size != 1) then
raise Puppet::ParseError, 'encode_url_queries_for_python(): Wrong number of arguments'
end
queries = args[0]
if queries.class != Hash
raise Puppet::ParseError, "encode_url_queries_for_python(): Requires a Hash, got #{queries.class}"
end
if queries.empty?
return ''
end
return '?' + URI.encode_www_form(queries).gsub(/%/, '%%')
end
end