Skip to content

Commit

Permalink
Merge pull request #8612 from ThomasWaldmann/yesno-ignore-unicode-err…
Browse files Browse the repository at this point in the history
…or-master

yes: deal with UnicodeDecodeError in input(), fixes #6984
  • Loading branch information
ThomasWaldmann authored Dec 29, 2024
2 parents 0c3269f + 9d1107e commit 35c56b9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/borg/helpers/yes_no.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
TRUISH = ("Yes", "YES", "yes", "Y", "y", "1")
DEFAULTISH = ("Default", "DEFAULT", "default", "D", "d", "")

ERROR = "error"
assert ERROR not in TRUISH + FALSISH + DEFAULTISH


def yes(
msg=None,
Expand Down Expand Up @@ -88,10 +91,14 @@ def output(msg, msg_type, is_prompt=False, **kwargs):
if not prompt:
return default
try:
answer = input()
answer = input() # this may raise UnicodeDecodeError, #6984
if answer == ERROR: # for testing purposes
raise UnicodeDecodeError("?", b"?", 0, 1, "?") # args don't matter
except EOFError:
# avoid defaultish[0], defaultish could be empty
answer = truish[0] if default else falsish[0]
except UnicodeDecodeError:
answer = ERROR
if answer in defaultish:
if default_msg:
output(default_msg, "accepted_default")
Expand Down

0 comments on commit 35c56b9

Please sign in to comment.