diff --git a/CHANGELOG.md b/CHANGELOG.md index f3f6962..bd1f53b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Upcoming + +- Add `noTrim` option to exec methods for cases where you do not want node-ssh to automatically trim the outputs. + #### 13.1.0 - Add new methods around sockets forwarding. #460 (Thanks @mat-sz) diff --git a/README.md b/README.md index a41e81d..d71a1b9 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ export interface SSHExecCommandOptions { stdin?: string | stream.Readable execOptions?: ExecOptions encoding?: BufferEncoding + noTrim?: boolean onChannel?: (clientChannel: ClientChannel) => void onStdout?: (chunk: Buffer) => void onStderr?: (chunk: Buffer) => void diff --git a/src/index.ts b/src/index.ts index 338c965..96dc3bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -369,6 +369,7 @@ export class NodeSSH { options.onStderr == null || typeof options.onStderr === 'function', 'options.onStderr must be a valid function', ) + invariant(options.noTrim == null || typeof options.noTrim === 'boolean', 'options.noTrim must be a boolean') let command = givenCommand @@ -428,8 +429,8 @@ export class NodeSSH { resolve({ code: code != null ? code : null, signal: signal != null ? signal : null, - stdout: stdout, - stderr: stderr, + stdout, + stderr, }) }) }) diff --git a/test/main-test.ts b/test/main-test.ts index 56f91e6..34adc55 100644 --- a/test/main-test.ts +++ b/test/main-test.ts @@ -494,3 +494,11 @@ sshit('forwards an inbound TCP/IP connection to client with automatically assign connectWithPassword(port, client) }) }) +sshit('has a working noTrim option', async function (t, port, client) { + await connectWithPassword(port, client) + const resultWithTrim = await client.exec('echo', ["\nhello\n\n\n\n"], {stream: 'stdout'}) + t.is(resultWithTrim, 'hello') + + const resultWithoutTrim = await client.exec('echo', ['\n\n\nhi\n\n\n'], {stream: 'stdout', noTrim: true}) + t.is(resultWithoutTrim, '\n\n\nhi\n\n\n\n') +})