1 | var assert = require('assert');
|
2 | var shellescape = require('./shellEscape');
|
3 |
|
4 |
|
5 | var args = ['curl', '-v', '-H', 'Location;', '-H', 'User-Agent: dave#10', 'http://www.daveeddy.com/?name=dave&age=24'];
|
6 |
|
7 | var escaped = shellescape(args);
|
8 |
|
9 | assert.strictEqual(escaped, "curl -v -H 'Location;' -H 'User-Agent: dave#10' 'http://www.daveeddy.com/?name=dave&age=24'");
|
10 | console.log(escaped);
|
11 |
|
12 |
|
13 |
|
14 | var d = {
|
15 | "echo 'hello\\nworld'": ['echo', 'hello\\nworld'],
|
16 | "echo 'hello\\tworld'": ['echo', 'hello\\tworld'],
|
17 | "echo '\thello\nworld'\\'": ['echo', '\thello\nworld\''],
|
18 | "echo 'hello world'": ['echo', 'hello world'],
|
19 | "echo hello world": ['echo', 'hello', 'world'],
|
20 | "echo 'hello\\\\'\\' \\''\\\\'\\''world'": ["echo", "hello\\\\'", "'\\\\'world"],
|
21 | "echo hello 'world\\'": ["echo", "hello", "world\\"]
|
22 | };
|
23 |
|
24 | Object.keys(d).forEach(function(s) {
|
25 | var escaped = shellescape(d[s]);
|
26 | assert.strictEqual(escaped, s);
|
27 | console.log(s);
|
28 | });
|
29 |
|
30 |
|
31 |
|
32 | var args = ['echo', 'hello!', 'how are you doing $USER', '"double"', "'single'"];
|
33 |
|
34 | var escaped = shellescape(args);
|
35 | assert.strictEqual(escaped, "echo 'hello!' 'how are you doing $USER' '\"double\"' \\''single'\\'");
|
36 | console.log(escaped);
|
37 |
|
38 |
|
39 | var escaped = shellescape(['cat', 'file.csv', '>', 'otherthing.csv']);
|
40 | assert.strictEqual(escaped, "cat 'file.csv' > 'otherthing.csv'");
|
41 | console.log(escaped);
|
42 |
|
43 | var escaped = shellescape(['cat', 'file.csv', '|', 'mappy', '>', 'otherthing.csv']);
|
44 | assert.strictEqual(escaped, "cat 'file.csv' | mappy > 'otherthing.csv'");
|
45 | console.log(escaped);
|
46 |
|
47 | var escaped = shellescape(['cat', 'file.csv?&', '|', 'mappy', '>', 'otherthing.csv']);
|
48 | assert.strictEqual(escaped, "cat 'file.csv?&' | mappy > 'otherthing.csv'");
|
49 | console.log(escaped);
|
50 |
|
51 | var escaped = shellescape(['hi\'?']);
|
52 | console.log(escaped);
|
53 | assert.strictEqual(escaped, "'hi'\\''?'"); |
\ | No newline at end of file |