Skip to content

Commit 24aa9a7

Browse files
authored
Merge pull request #120 from launchcodedev/fix/secret-encrypt-stdin-newlines
Fix: Keep newlines when encrypting from stdin
2 parents 64e8f73 + b82e573 commit 24aa9a7

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

app-config-node/src/prompts.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ describe('consumeStdin', () => {
3737
.then(() => end())
3838
.catch(() => {});
3939

40-
// we expect newlines to be eaten up, since this function is used for html and base64 data
41-
expect(await consumeStdin()).toBe('foobarbaz');
40+
expect(await consumeStdin()).toBe('foo\nbar\nbaz\n');
4241
});
4342
});
4443
});

app-config-node/src/prompts.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import readline from 'readline';
2-
import prompts from 'prompts';
3-
import type { PromptObject } from 'prompts';
41
import { AppConfigError } from '@app-config/core';
52
import { logger } from '@app-config/logging';
3+
import type { PromptObject } from 'prompts';
4+
import prompts from 'prompts';
65

76
export async function promptUser<T>(options: Omit<PromptObject, 'name'>): Promise<T> {
87
const { named } = await prompts({ ...options, name: 'named' });
@@ -31,14 +30,9 @@ export async function promptUserWithRetry<T>(
3130

3231
export async function consumeStdin(): Promise<string> {
3332
return new Promise((resolve, reject) => {
34-
const rl = readline.createInterface({ input: process.stdin });
35-
36-
let buffer = '';
37-
rl.on('line', (line) => {
38-
buffer += line;
39-
});
40-
41-
rl.on('error', reject);
42-
rl.on('close', () => resolve(buffer));
33+
const buffers: Buffer[] = [];
34+
process.stdin.on('data', (data) => buffers.push(data));
35+
process.stdin.on('error', reject);
36+
process.stdin.on('end', () => resolve(Buffer.concat(buffers).toString('utf8')));
4337
});
4438
}

0 commit comments

Comments
 (0)