From 855157ed06d83cf4ce29b5f952e811c0c63b27bd Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Fri, 9 Mar 2018 12:07:06 +0900 Subject: [PATCH 1/2] add backslash test --- src/__tests__/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 985df57..f009d6c 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -133,6 +133,21 @@ it(`should propagate kill signals`, () => { expect(crossSpawnMock.__mock.spawned.kill).toHaveBeenCalledWith('SIGBREAK') }) +it(`should keep backslashes`, () => { + isWindowsMock.__mock.returnValue = true + crossEnv(['echo', '\\\\\\\\someshare\\\\somefolder']) + expect(crossSpawnMock.spawn).toHaveBeenCalledWith( + 'echo', + ['\\\\someshare\\somefolder'], + { + stdio: 'inherit', + env: Object.assign({}, process.env), + }, + ) + isWindowsMock.__mock.reset() +}) + + function testEnvSetting(expected, ...envSettings) { if (expected.APPDATA === 2) { // kill the APPDATA to test both is undefined From e40b572c7a283c304d2235289070a1ec0b63f4fe Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Fri, 9 Mar 2018 12:07:58 +0900 Subject: [PATCH 2/2] allow escaped backslash through --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 45ad1a3..9db75a7 100644 --- a/src/index.js +++ b/src/index.js @@ -58,9 +58,10 @@ function parseCommand(args) { // match "\'" or "'" // or match "\" if followed by [$"\] (lookahead) .map(a => { - const re = /(\\)?'|([\\])(?=[$"\\])/g + const re = /\\\\|(\\)?'|([\\])(?=[$"\\])/g // Eliminate all matches except for "\'" => "'" return a.replace(re, m => { + if (m === "\\\\") return "\\" if (m === "\\'") return "'" return '' })