Patchwork [1,of,2] py3: decode prompt string before calling rawinput

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 9, 2019, 1:29 p.m.
Message ID <99f06850be3ecc521ba4.1570627763@steppe.local>
Download mbox | patch
Permalink /patch/42134/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 9, 2019, 1:29 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1570627696 -7200
#      Wed Oct 09 15:28:16 2019 +0200
# Node ID 99f06850be3ecc521ba461684686865c1191c5a0
# Parent  1fcf79e9943a17a2e7ae19954b2b5ad5972f8fff
py3: decode prompt string before calling rawinput

Calling input() (aka pycompat.rawinput() on python3) with a byte string
displays a byte string in the console. E.g. in interactive commit, we
get: b"examine changes to '<file>'?\n(enter ? for help) [Ynesfdaq?]".
Similarly, "hg email" prompts are messed up.

We thus decode the prompt string before running rawinput().
Pulkit Goyal - Oct. 9, 2019, 2:26 p.m.
On Wed, Oct 9, 2019 at 4:38 PM Denis Laxalde <denis@laxalde.org> wrote:
>
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1570627696 -7200
> #      Wed Oct 09 15:28:16 2019 +0200
> # Node ID 99f06850be3ecc521ba461684686865c1191c5a0
> # Parent  1fcf79e9943a17a2e7ae19954b2b5ad5972f8fff
> py3: decode prompt string before calling rawinput
>
> Calling input() (aka pycompat.rawinput() on python3) with a byte string
> displays a byte string in the console. E.g. in interactive commit, we
> get: b"examine changes to '<file>'?\n(enter ? for help) [Ynesfdaq?]".
> Similarly, "hg email" prompts are messed up.
>
> We thus decode the prompt string before running rawinput().

Queued these, many thanks!

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
index b8cac79..432f53e 100644
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1555,6 +1555,7 @@  class ui(object):
         # - http://bugs.python.org/issue12833
         with self.timeblockedsection(b'stdio'):
             if usereadline:
+                prompt = encoding.strfromlocal(prompt)
                 line = encoding.strtolocal(pycompat.rawinput(prompt))
                 # When stdin is in binary mode on Windows, it can cause
                 # raw_input() to emit an extra trailing carriage return