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

No trim follow up #476

Merged
merged 5 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
Loading