Tweaks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sindre Sorhus · committed by Sindre Sorhus · parent bfe4633 · Browse files · 5 files·+18 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+18 added−5 removed
- tests:+8 added−0 removed
- other:+10 added−5 removed
Provenance
- Commit
54d7404- Tree
a09cb6b- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
bfe4633
5 files changed+18 added−5 removed
modified:.github/workflows/main.yml+1 added-1 removed
22 unmodified lines2324252627272829303114 unmodified lines22 unmodified lines path: .lycheecache key: cache-lychee-${{ github.sha }} restore-keys: cache-lychee- - uses: actions/checkout@v7 - uses: actions/setup-node@v6 - uses: actions/setup-node@v7 with: node-version: ${{ matrix.node-version }} - run: npm install - uses: lycheeverse/lychee-action@v214 unmodified linesmodified:.github/security.md+1 added
6 unmodified lines78910116 unmodified lines## Not vulnerabilities
- Command injection through the `shell` option, or through a command or options that come from untrusted input. Only arguments are escaped.- On Windows, a batch file that misuses its arguments, like `if "%1" == ""`. No escaping can prevent this. See [Windows escaping](https://github.com/sindresorhus/execa/blob/main/docs/windows.md#escaping).- Prototype pollution, except of the top-level options. Node.js itself is not safe from it.modified:docs/errors.md+2 added
8 unmodified lines910111213141516171894 unmodified lines8 unmodified lines## Subprocess failure
When the subprocess fails, the promise returned by [`execa()`](api.md#execafile-arguments-options) is rejected with an [`ExecaError`](api.md#execaerror) instance. The `error` has the same shape as successful [results](api.md#result), with a few additional [error-specific fields](api.md#execaerror). [`error.failed`](api.md#resultfailed) is always `true`.
When the subprocess fails to spawn, its output ([`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr), [`error.all`](api.md#resultall) and [`error.stdio`](api.md#resultstdio)) is usually empty. With some errors, it is `undefined` instead.
```jsimport {execa, ExecaError} from 'execa';
try {94 unmodified linesmodified:lib/io/output-sync.js+6 added-4 removed
40 unmodified lines41 const uint8ArrayResult = bufferToUint8Array(truncatedResult);42 const {stdioItems, objectMode} = fileDescriptors[fdNumber];43 // Empty output must not be passed as a chunk: with a binary encoding, no line is split, so transforms would wrongly run on it44 const {chunks, error: transformError} = runOutputGeneratorsSync(uint8ArrayResult.length === 0 ? [] : [uint8ArrayResult], stdioItems, encoding);45- const {serializedResult, finalResult = serializedResult} = serializeChunks({45+ const {serializedResult, finalResult} = serializeChunks({46 chunks,47 objectMode,48 encoding,49 lines,41 unmodified lines91 // - serializedResult: used by `verbose`92 // - finalResult/returnedResult: returned as `result.std*`93 const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber}) => {94 if (objectMode) {95- return {serializedResult: chunks};95+ return {serializedResult: chunks, finalResult: chunks};96 }97 98 if (encoding === 'buffer') {99- return {serializedResult: joinToUint8Array(chunks)};99+ const serializedResult = joinToUint8Array(chunks);100+ return {serializedResult, finalResult: serializedResult};101 }102 103 const serializedResult = joinToString(chunks, encoding);103- return lines[fdNumber] ? {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline[fdNumber], objectMode)} : {serializedResult};104+ const finalResult = lines[fdNumber] ? splitLinesSync(serializedResult, !stripFinalNewline[fdNumber], objectMode) : serializedResult;105+ return {serializedResult, finalResult};106 };107 108 const logOutputSync = ({serializedResult, fdNumber, verboseInfo, encoding, stdioItems, objectMode}) => {109 if (!shouldLogOutput({51 unmodified linesmodified:test/arguments/prototype-pollution.js+8 added
255 unmodified lines256 257 const {code} = execaSync('non-existent-command', {reject: false});258 assert.equal(code, 'ENOENT');259 });260+261+// Without `lines`, the output has no `finalResult` property, which must not be read from the prototype262+test('Polluted "finalResult" is ignored, sync', t => {263+ pollutePrototype(t, {finalResult: foobarString});264+265+ const {stdout} = execaSync('empty.js');266+ assert.equal(stdout, '');267+});