Escape case where password ends with '$'.

postgresql_escape returned an invalid string if the password end in '$':
    postgres=# alter role "postgres" password $$foo$$$;
    ERROR:  syntax error at or near "$"
    LINE 1: alter role "postgres" password $$foo$$$;
This commit is contained in:
Farzad FARID 2016-02-01 19:27:22 +01:00
parent f7dfa262dc
commit 810448afa0
2 changed files with 6 additions and 2 deletions

View file

@ -11,7 +11,7 @@ module Puppet::Parser::Functions
password = args[0]
if password !~ /\$\$/
if password !~ /\$\$/ and password[-1] != '$'
retval = "$$#{password}$$"
else
escape = Digest::MD5.hexdigest(password)[0..5].gsub(/\d/,'')
@ -20,6 +20,6 @@ module Puppet::Parser::Functions
end
retval = "$#{escape}$#{password}$#{escape}$"
end
retval
retval
end
end

View file

@ -8,3 +8,7 @@ describe 'postgresql_escape', :type => :puppet_function do
it { is_expected.to run.with_params('fo$$o').
and_return('$ed$fo$$o$ed$') }
end
describe 'postgresql_escape', :type => :puppet_function do
it { is_expected.to run.with_params('foo$').
and_return('$a$foo$$a$') }
end