From adae66f47cf11bb7a686c98059436f496d881955 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 14 Apr 2013 21:17:29 -0700 Subject: [PATCH] cleaner implementation recursing on the double quote case --- index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8b339c5..65f663b 100644 --- a/index.js +++ b/index.js @@ -30,16 +30,13 @@ exports.parse = function parse (s, env) { .replace(/\\([ "'\\$`(){}!#&*|])/g, '$1') ; } - else return s - .replace(/(['"])((\\\1|[^\1])*?)\1|[^'"]+/g, function (s, q) { + else return s.replace( + /(['"])((\\\1|[^\1])*?)\1|[^'"]+/g, + function (s, q) { if (/^['"]/.test(s)) return parse(s, env); - return s - .replace(/(^|[^\\])\$(\w+)/g, getVar) - .replace(/(^|[^\\])\${(\w+)}/g, getVar) - .replace(/\\([ "'\\$`(){}!#&*|])/g, '$1') - ; - }) - ; + return parse('"' + s + '"', env); + } + ); }); function getVar (_, pre, key) {