Skip to content

Commit

Permalink
Merge pull request #476 from steelbrain/stelbrain/no-trim-followup
Browse files Browse the repository at this point in the history
No trim follow up
  • Loading branch information
steelbrain committed Apr 20, 2024
2 parents c4bc27f + 8b49f1a commit 53f58b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -428,8 +429,8 @@ export class NodeSSH {
resolve({
code: code != null ? code : null,
signal: signal != null ? signal : null,
stdout: stdout,
stderr: stderr,
stdout,
stderr,
})
})
})
Expand Down
8 changes: 8 additions & 0 deletions test/main-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit 53f58b4

Please sign in to comment.