Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yes: deal with UnicodeDecodeError in input(), fixes #6984 #8612

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 96 in src/borg/helpers/yes_no.py

View check run for this annotation

Codecov / codecov/patch

src/borg/helpers/yes_no.py#L96

Added line #L96 was not covered by tests
except EOFError:
# avoid defaultish[0], defaultish could be empty
answer = truish[0] if default else falsish[0]
except UnicodeDecodeError:
answer = ERROR

Check warning on line 101 in src/borg/helpers/yes_no.py

View check run for this annotation

Codecov / codecov/patch

src/borg/helpers/yes_no.py#L100-L101

Added lines #L100 - L101 were not covered by tests
if answer in defaultish:
if default_msg:
output(default_msg, "accepted_default")
Expand Down
Loading