[Pkg-javascript-commits] [node-shell-quote] 03/137: passing the parse test

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 19:19:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-shell-quote.

commit 69c0f8529825d3fdc700e81d32b75378cef47994
Author: James Halliday <mail at substack.net>
Date:   Fri May 18 03:23:36 2012 -0700

    passing the parse test
---
 index.js      | 18 +++++++++++++++++-
 test/parse.js |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 4cf466f..3c77961 100644
--- a/index.js
+++ b/index.js
@@ -13,5 +13,21 @@ exports.quote = function (xs) {
 };
 
 exports.parse = function (s) {
-    return s.match(/(['"])((\\\1|[^\1])*?)\1|\S+/g);
+    return s.match(/(['"])((\\\1|[^\1])*?)\1|\S+/g)
+        .map(function (s) {
+            if (/^'/.test(s)) {
+                return s
+                    .replace(/^'|'$/g, '')
+                    .replace(/\\(['\\])/g, '$1')
+                ;
+            }
+            else if (/^"/.test(s)) {
+                return s
+                    .replace(/^"|"$/g, '')
+                    .replace(/\\(["\\])/g, '$1')
+                ;
+            }
+            else return s;
+        })
+    ;
 };
diff --git a/test/parse.js b/test/parse.js
index 24522eb..f3c4e61 100644
--- a/test/parse.js
+++ b/test/parse.js
@@ -2,7 +2,7 @@ var test = require('tap').test;
 var parse = require('../').parse;
 
 test('parse shell commands', function (t) {
-    t.same('a \'b\' "c"', [ 'a', 'b', 'c' ]);
+    t.same(parse('a \'b\' "c"'), [ 'a', 'b', 'c' ]);
     
     t.same(
         parse('beep "boop" \'foo bar baz\' "it\'s \\"so\\" groovy"'),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-shell-quote.git



More information about the Pkg-javascript-commits mailing list