Puppet Function: postgresql::postgresql_escape
  
    - Defined in:
 
    - 
      lib/puppet/functions/postgresql/postgresql_escape.rb
    
 
  
  
    - Function type:
 
    - Ruby 4.x API
 
  
 
  Summary
  This function escapes a string using [Dollar Quoting](https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING) using a randomly generated tag if required.
Overview
  
  
    
      
        postgresql::postgresql_escape(String[1] $input_string) ⇒ String 
      
    
  
  
  
  
  
    
      
        
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 
       | 
      
        # File 'lib/puppet/functions/postgresql/postgresql_escape.rb', line 6
Puppet::Functions.create_function(:'postgresql::postgresql_escape') do
            dispatch :default_impl do
    param 'String[1]', :input_string
  end
  def default_impl(input_string)
        return "$$#{input_string}$$" unless tag_needed?(input_string)
        tag = Digest::MD5.hexdigest(input_string)[0..5].gsub(%r{\d}, '')
    tag = Digest::MD5.hexdigest(tag)[0..5].gsub(%r{\d}, '') until input_string !~ %r{#{tag}}
    "$#{tag}$#{input_string}$#{tag}$"
  end
  def tag_needed?(input_string)
    input_string.include?('$$') || input_string.end_with?('$')
  end
end
       |