From a1ca64d00547d09eda824a8f9d7f797f7f8d0961 Mon Sep 17 00:00:00 2001 From: avallete Date: Mon, 15 Jun 2026 13:48:04 +0200 Subject: [PATCH] fix: normalize password prompt empty submit to empty string (#560) The password prompt resolved to undefined on empty submit instead of empty string. Normalize the value on finalize to match the text prompt and the documented Promise return type. --- .changeset/password-empty-submit.md | 5 +++++ packages/core/src/prompts/password.ts | 5 +++++ packages/core/test/prompts/password.test.ts | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 .changeset/password-empty-submit.md diff --git a/.changeset/password-empty-submit.md b/.changeset/password-empty-submit.md new file mode 100644 index 00000000..967e323d --- /dev/null +++ b/.changeset/password-empty-submit.md @@ -0,0 +1,5 @@ +--- +"@clack/core": patch +--- + +Fix `password` prompt resolving to `undefined` on empty submit. It now normalizes an empty submission to `""`, matching the `text` prompt behavior and the documented `Promise` return type. diff --git a/packages/core/src/prompts/password.ts b/packages/core/src/prompts/password.ts index 949239d1..738d973b 100644 --- a/packages/core/src/prompts/password.ts +++ b/packages/core/src/prompts/password.ts @@ -34,5 +34,10 @@ export default class PasswordPrompt extends Prompt { this.on('userInput', (input) => { this._setValue(input); }); + this.on('finalize', () => { + if (this.value === undefined) { + this.value = ''; + } + }); } } diff --git a/packages/core/test/prompts/password.test.ts b/packages/core/test/prompts/password.test.ts index 3b37e9d3..1142ca9c 100644 --- a/packages/core/test/prompts/password.test.ts +++ b/packages/core/test/prompts/password.test.ts @@ -29,6 +29,18 @@ describe('PasswordPrompt', () => { expect(output.buffer).to.deep.equal([cursor.hide, 'foo']); }); + test('returns empty string on empty submit', async () => { + const instance = new PasswordPrompt({ + input, + output, + render: () => 'foo', + }); + const resultPromise = instance.prompt(); + input.emit('keypress', '', { name: 'return' }); + const result = await resultPromise; + expect(result).to.equal(''); + }); + describe('cursor', () => { test('can get cursor', () => { const instance = new PasswordPrompt({