diff --git a/lib/puppet/parser/functions/postgresql_escape.rb b/lib/puppet/parser/functions/postgresql_escape.rb index 4089a4e..1ec11b8 100644 --- a/lib/puppet/parser/functions/postgresql_escape.rb +++ b/lib/puppet/parser/functions/postgresql_escape.rb @@ -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 diff --git a/spec/unit/functions/postgresql_escape_spec.rb b/spec/unit/functions/postgresql_escape_spec.rb index f7eec6a..b4c9488 100644 --- a/spec/unit/functions/postgresql_escape_spec.rb +++ b/spec/unit/functions/postgresql_escape_spec.rb @@ -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