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 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 '' })