Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit 450dae9

Browse files
greggmanKent C. Dodds
authored andcommitted
fix: allow backslash (#173)
* add backslash test * allow escaped backslash through
1 parent 5204dd6 commit 450dae9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/__tests__/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ it(`should propagate kill signals`, () => {
133133
expect(crossSpawnMock.__mock.spawned.kill).toHaveBeenCalledWith('SIGBREAK')
134134
})
135135

136+
it(`should keep backslashes`, () => {
137+
isWindowsMock.__mock.returnValue = true
138+
crossEnv(['echo', '\\\\\\\\someshare\\\\somefolder'])
139+
expect(crossSpawnMock.spawn).toHaveBeenCalledWith(
140+
'echo',
141+
['\\\\someshare\\somefolder'],
142+
{
143+
stdio: 'inherit',
144+
env: Object.assign({}, process.env),
145+
},
146+
)
147+
isWindowsMock.__mock.reset()
148+
})
149+
150+
136151
function testEnvSetting(expected, ...envSettings) {
137152
if (expected.APPDATA === 2) {
138153
// kill the APPDATA to test both is undefined

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ function parseCommand(args) {
5858
// match "\'" or "'"
5959
// or match "\" if followed by [$"\] (lookahead)
6060
.map(a => {
61-
const re = /(\\)?'|([\\])(?=[$"\\])/g
61+
const re = /\\\\|(\\)?'|([\\])(?=[$"\\])/g
6262
// Eliminate all matches except for "\'" => "'"
6363
return a.replace(re, m => {
64+
if (m === "\\\\") return "\\"
6465
if (m === "\\'") return "'"
6566
return ''
6667
})

0 commit comments

Comments
 (0)