[Request] [+ ] D11240: windows: avoid a bytes vs unicode crash reading passwords on py2

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Mon Aug 2 15:00:47 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This broke in 5b3513177f2b <https://phab.mercurial-scm.org/rHG5b3513177f2b449ff49f0879d5cf9d81e69a43a6>.  Specifically, after typing in the password on py2,
  it would crash with:
  
    TypeError: putwch() argument 1 must be cannot convert raw buffers, not str

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D11240

AFFECTED FILES
  mercurial/windows.py

CHANGE DETAILS

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -200,20 +200,20 @@
     This shouldn't be called directly- use ``ui.getpass()`` instead, which
     checks if the session is interactive first.
     """
-    pw = ""
+    pw = u""
     while True:
         c = msvcrt.getwch()  # pytype: disable=module-attr
-        if c == '\r' or c == '\n':
+        if c == u'\r' or c == u'\n':
             break
-        if c == '\003':
+        if c == u'\003':
             raise KeyboardInterrupt
-        if c == '\b':
+        if c == u'\b':
             pw = pw[:-1]
         else:
             pw = pw + c
-    msvcrt.putwch('\r')  # pytype: disable=module-attr
-    msvcrt.putwch('\n')  # pytype: disable=module-attr
-    return encoding.strtolocal(pw)
+    msvcrt.putwch(u'\r')  # pytype: disable=module-attr
+    msvcrt.putwch(u'\n')  # pytype: disable=module-attr
+    return encoding.unitolocal(pw)
 
 
 class winstdout(object):



To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210802/e07ddae8/attachment.html>


More information about the Mercurial-patches mailing list