Sha256: ef28d174a50acdcb203da9245bca513730668cd9ef5cd3ad4cce3053e8677388

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

module Puppet::Parser::Functions

  Safe = 'a-zA-Z0-9@%_+=:,./-'    # Safe unquoted
  Dangerous = '!"`$\\'            # Unsafe inside double quotes

  newfunction(:shellquote, :type => :rvalue, :doc => "\
    Quote and concatenate arguments for use in Bourne shell.

    Each argument is quoted separately, and then all are concatenated
    with spaces.  If an argument is an array, the elements of that
    array is interpolated within the rest of the arguments; this makes
    it possible to have an array of arguments and pass that array to
    shellquote instead of having to specify each argument
    individually in the call.
    ") \
  do |args|

    result = []
    args.flatten.each do |word|
      if word.length != 0 and word.count(Safe) == word.length
        result << word
      elsif word.count(Dangerous) == 0
        result << ('"' + word + '"')
      elsif word.count("'") == 0
        result << ("'" + word + "'")
      else
        r = '"'
        word.each_byte do |c|
          r += "\\" if Dangerous.include?(c)
          r += c.chr
        end
        r += '"'
        result << r
      end
    end

    return result.join(" ")
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-2.6.18 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.17 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.16 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.15 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.14 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.13 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.12 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.11 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.10 lib/puppet/parser/functions/shellquote.rb
puppet-2.7.1 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.9 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.8 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.7 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.6 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.5 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.4 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.3 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.2 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.1 lib/puppet/parser/functions/shellquote.rb
puppet-2.6.0 lib/puppet/parser/functions/shellquote.rb