Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not being able to escape more than one space in commands #262

Merged
merged 4 commits into from May 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions fixtures/command with space
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict';
console.log(process.argv.slice(2).join('\n'));
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -23,13 +23,13 @@ function handleEscaping(tokens, token, index) {
return [token];
}

const previousToken = tokens[index - 1];
const previousToken = tokens[tokens.length - 1];

if (!previousToken.endsWith('\\')) {
ehmicky marked this conversation as resolved.
Show resolved Hide resolved
return [...tokens, token];
}

return [...tokens.slice(0, index - 1), `${previousToken.slice(0, -1)} ${token}`];
return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`];
}

function parseCommand(command, args = []) {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Expand Up @@ -123,6 +123,11 @@ test('escape other whitespaces in string arguments', async t => {
t.is(stdout, 'foo\tbar');
});

test('allow escaping spaces in commands', async t => {
const {stdout} = await execa('./fixtures/command\\ with\\ space foo bar');
t.is(stdout, 'foo\nbar');
});

test('allow escaping spaces in string arguments', async t => {
const {stdout} = await execa('node fixtures/echo foo\\ bar');
t.is(stdout, 'foo bar');
Expand Down