3
require File.dirname(__FILE__) + '/../../../spec_helper'
5
describe "the shellquote function" do
8
@scope = Puppet::Parser::Scope.new()
12
Puppet::Parser::Functions.function("shellquote").should == "function_shellquote"
16
it "should handle no arguments" do
17
result = @scope.function_shellquote([])
18
result.should(eql(""))
21
it "should handle several simple arguments" do
22
result = @scope.function_shellquote(
23
['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
25
'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
28
it "should handle array arguments" do
29
result = @scope.function_shellquote(
30
['foo', ['bar@example.com', 'localhost:/dev/null'],
33
'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
36
it "should quote unsafe characters" do
37
result = @scope.function_shellquote(
38
['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
40
'"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
43
it "should deal with double quotes" do
44
result = @scope.function_shellquote(
50
it "should cope with dollar signs" do
51
result = @scope.function_shellquote(
52
['$PATH', 'foo$bar', '"x$"'])
54
"'$PATH' 'foo$bar' '\"x$\"'"))
57
it "should deal with apostrophes (single quotes)" do
58
result = @scope.function_shellquote(
59
["'foo'bar'", "`$'EDITOR'`"])
61
'"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"'))
64
it "should cope with grave accents (backquotes)" do
65
result = @scope.function_shellquote(
66
['`echo *`', '`ls "$MAILPATH"`'])
68
"'`echo *`' '`ls \"$MAILPATH\"`'"))
71
it "should deal with both single and double quotes" do
72
result = @scope.function_shellquote(
73
['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
75
'"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
78
it "should handle multiple quotes *and* dollars and backquotes" do
79
result = @scope.function_shellquote(
80
['\'foo"$x`bar`"xyzzy\''])
82
'"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
85
it "should handle linefeeds" do
86
result = @scope.function_shellquote(