diff --git a/parse.js b/parse.js index f4c46a7..1fff1bc 100644 --- a/parse.js +++ b/parse.js @@ -3,7 +3,7 @@ // '<(' is process substitution operator and // can be parsed the same as control operator var CONTROL = '(?:' + [ - '\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '>>', '>\\&', '<\\&', '[&;()|<>]' + '\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '\\<\\<\\<', '>>', '>\\&', '<\\&', '[&;()|<>]' ].join('|') + ')'; var META = '|&;()<> \\t'; var BAREWORD = '(\\\\[\'"' + META + ']|[^\\s\'"' + META + '])+'; diff --git a/test/env.js b/test/env.js index deb854b..4cc0a51 100644 --- a/test/env.js +++ b/test/env.js @@ -23,6 +23,15 @@ test('expand environment variables', function (t) { t.end(); }); +test('expand environment variables within here-strings', function (t) { + t.same(parse('a <<< $x', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< ${x}', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< "$x"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< "${x}"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + + t.end(); +}); + test('environment variables with metacharacters', function (t) { t.same(parse('a $XYZ c', { XYZ: '"b"' }), ['a', '"b"', 'c']); t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), ['a', '$X', 'c']); diff --git a/test/op.js b/test/op.js index d665f11..38d3757 100644 --- a/test/op.js +++ b/test/op.js @@ -82,6 +82,15 @@ test('duplicating input file descriptors', function (t) { t.end(); }); +test('here strings', function (t) { + t.same(parse('cat <<< "hello world"'), ['cat', { op: '<<<' }, 'hello world']); + t.same(parse('cat <<< hello'), ['cat', { op: '<<<' }, 'hello']); + t.same(parse('cat<<