Skip to content

Commit

Permalink
one more test passing with quote recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Apr 15, 2013
1 parent c669d2e commit e9537b9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ exports.quote = function (xs) {
}).join(' ');
};

var re = {
chunk: /(['"])((\\\1|[^\1])*?)\1|(\\ |\S)+/g
};

exports.parse = function parse (s, env) {
if (!env) env = {};
return s.match(re.chunk).map(function (s) {
var chunker = /(['"])((\\\1|[^\1])*?)\1|(\\ |\S)+/g;
return s.match(chunker).map(function (s) {
if (/^'/.test(s)) {
return s
.replace(/^'|'$/g, '')
Expand All @@ -36,6 +33,9 @@ exports.parse = function parse (s, env) {
else return s
.replace(/(^|[^\\])\$(\w+)/g, getVar)
.replace(/(^|[^\\])\${(\w+)}/g, getVar)
.replace(/(['"])((\\\1|[^\1])*?)\1/, function (_, q, s) {
return parse(s, env);
})
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
;
});
Expand Down

0 comments on commit e9537b9

Please sign in to comment.