From 43167267377bf7a518eafb7f94105e5d2c6d236e Mon Sep 17 00:00:00 2001 From: Matt Hoyle Date: Fri, 12 Feb 2016 14:52:30 +0000 Subject: [PATCH 1/2] Add arg substitution for shell special chars Based on the list of special chars in http://stackoverflow.com/a/7685469/1318694 --- src/git.coffee | 5 ++++- test/repo.test.coffee | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/git.coffee b/src/git.coffee index 9ae188a..8669b05 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -12,7 +12,10 @@ module.exports = Git = (git_dir, dot_git, git_options) -> options = options_to_argv options options = options.join " " args ?= [] - args = args.join " " if args instanceof Array + if args instanceof Array + shell_args = for arg in args + arg.replace(/(["\s'$`\\])/g,'\\$1') + args = shell_args.join " " encoding ?= 'utf8' bash = "#{git_options.bin || Git.bin} #{command} #{options} #{args}" exec bash, { diff --git a/test/repo.test.coffee b/test/repo.test.coffee index a0ce37b..44bc43e 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -18,7 +18,7 @@ describe "Repo", -> describe "#add", -> repo = null - git_dir = __dirname + "/fixtures/junk_add" + git_dir = __dirname + "/fixtures/junk _$add" status = null file = null From 0f8b221055b624d9a7646f5294c3e4cf47fce4ff Mon Sep 17 00:00:00 2001 From: Matt Hoyle Date: Fri, 12 Feb 2016 15:09:24 +0000 Subject: [PATCH 2/2] Fix for failing identify test `identify` was placing double quotes around the string which were being escaped and included via the new arg processor --- src/repo.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/repo.coffee b/src/repo.coffee index 3c0e2be..06864e0 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -44,10 +44,10 @@ module.exports = class Repo # identify: (actor, callback) -> # git config user.email "you@example.com" - @git "config", {}, ["user.email", "\"#{actor.email}\""], (err) => + @git "config", {}, ["user.email", "#{actor.email}"], (err) => return callback err if err # git config user.name "Your Name" - @git "config", {}, ["user.name", "\"#{actor.name}\""], (err) => + @git "config", {}, ["user.name", "#{actor.name}"], (err) => return callback err if err return callback null