Skip to content
Myr

Merge pull request #2158 from unparalleled-js/fix/allow-empty-when-confirmation-required

Before adoption: this commit came in with the history the project adopted, so no landing records it.

allow empty str input in prompt() when confirmation_prompt=True and default=""

authored by David Lord · committed by GitHub · parents c01e2b8, 4f7b255 · Browse files · 3 files+15 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−7 removed

  • tests:+11 added−6 removed
  • other:+4 added−1 removed

3 files+15 added−7 removed

modified:src/click/termui.py+2 added-1 removed
179 unmodified lines
180 if not confirmation_prompt:181 return result182 while True:183 value2 = prompt_func(confirmation_prompt)184 if value2:184 is_empty = not value and not value2185 if value2 or is_empty:186 break187 if value == value2:188 return result189 echo(_("Error: The two entered values do not match."), err=err)
598 unmodified lines
modified:tests/test_termui.py+11 added-6 removed
418 unmodified lines
419 assert result.return_value == expect420421422@pytest.mark.parametrize(423 ("prompt", "input", "expect"),423 ("prompt", "input", "default", "expect"),424 [425 (True, "password\npassword", "password"),426 ("Confirm Password", "password\npassword\n", "password"),427 (False, None, None),425 (True, "password\npassword", None, "password"),426 ("Confirm Password", "password\npassword\n", None, "password"),427 (True, "", "", ""),428 (False, None, None, None),429 ],430)430def test_confirmation_prompt(runner, prompt, input, expect):431def test_confirmation_prompt(runner, prompt, input, default, expect):432 @click.command()433 @click.option(433 "--password", prompt=prompt, hide_input=True, confirmation_prompt=prompt434 "--password",435 prompt=prompt,436 hide_input=True,437 default=default,438 confirmation_prompt=prompt,439 )440 def cli(password):441 return password442
6 unmodified lines
modified:CHANGES.rst+2 added
34 unmodified lines
35 processed. :issue:`1985`36- Store unprocessed ``Command.help``, ``epilog`` and ``short_help``37 strings. Processing is only done when formatting help text for38 output. :issue:`2149`39- Allow empty str input for ``prompt()`` when40 ``confirmation_prompt=True`` and ``default=""``. :issue:`2157`414243Version 8.0.444-------------
948 unmodified lines