Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 5766371 · Browse files · 3 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−4 removed

  • other:+12 added−4 removed

3 files+12 added−4 removed

added:fixtures/command with space+3 added
1#!/usr/bin/env node2'use strict';3console.log(process.argv.slice(2).join('\n'));
modified:index.js+4 added-4 removed
21 unmodified lines
22 if (index === 0) {23 return [token];24 }2526 const previousToken = tokens[index - 1];26 const previousToken = tokens[tokens.length - 1];2728 if (!previousToken.endsWith('\\')) {29 return [...tokens, token];28 if (previousToken.endsWith('\\')) {29 return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`];30 }3132 return [...tokens.slice(0, index - 1), `${previousToken.slice(0, -1)} ${token}`];32 return [...tokens, token];33}3435function parseCommand(command, args = []) {36 if (args.length !== 0) {
427 unmodified lines
modified:test.js+5 added
121 unmodified lines
122 const {stdout} = await execa('node fixtures/echo foo\tbar');123 t.is(stdout, 'foo\tbar');124});125126test('allow escaping spaces in commands', async t => {127 const {stdout} = await execa('./fixtures/command\\ with\\ space foo bar');128 t.is(stdout, 'foo\nbar');129});130131test('allow escaping spaces in string arguments', async t => {132 const {stdout} = await execa('node fixtures/echo foo\\ bar');133 t.is(stdout, 'foo bar');134});
579 unmodified lines