summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunparalleled-js <yingthi@live.com>2021-12-23 18:37:29 -0600
committerDavid Lord <davidism@gmail.com>2022-02-21 12:18:46 -0800
commit4f7b255f70a4954077f282090e7059b8b7ead42d (patch)
treeb355b72c339f07b35ce5d357cb4f629f014dd5f6
parentc01e2b8ed17d3ea65981bc62784363d0e38e3092 (diff)
downloadclick-4f7b255f70a4954077f282090e7059b8b7ead42d.tar.gz
allow empty str input for prompt
-rw-r--r--CHANGES.rst2
-rw-r--r--src/click/termui.py3
-rw-r--r--tests/test_termui.py17
3 files changed, 15 insertions, 7 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 0bfa1d5..8a4887c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -36,6 +36,8 @@ Version 8.1.0
- Store unprocessed ``Command.help``, ``epilog`` and ``short_help``
strings. Processing is only done when formatting help text for
output. :issue:`2149`
+- Allow empty str input for ``prompt()`` when
+ ``confirmation_prompt=True`` and ``default=""``. :issue:`2157`
Version 8.0.4
diff --git a/src/click/termui.py b/src/click/termui.py
index 6645299..bfb2f5a 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -181,7 +181,8 @@ def prompt(
return result
while True:
value2 = prompt_func(confirmation_prompt)
- if value2:
+ is_empty = not value and not value2
+ if value2 or is_empty:
break
if value == value2:
return result
diff --git a/tests/test_termui.py b/tests/test_termui.py
index 5e819df..3123252 100644
--- a/tests/test_termui.py
+++ b/tests/test_termui.py
@@ -420,17 +420,22 @@ def test_prompt_required_false(runner, args, expect):
@pytest.mark.parametrize(
- ("prompt", "input", "expect"),
+ ("prompt", "input", "default", "expect"),
[
- (True, "password\npassword", "password"),
- ("Confirm Password", "password\npassword\n", "password"),
- (False, None, None),
+ (True, "password\npassword", None, "password"),
+ ("Confirm Password", "password\npassword\n", None, "password"),
+ (True, "", "", ""),
+ (False, None, None, None),
],
)
-def test_confirmation_prompt(runner, prompt, input, expect):
+def test_confirmation_prompt(runner, prompt, input, default, expect):
@click.command()
@click.option(
- "--password", prompt=prompt, hide_input=True, confirmation_prompt=prompt
+ "--password",
+ prompt=prompt,
+ hide_input=True,
+ default=default,
+ confirmation_prompt=prompt,
)
def cli(password):
return password