D7020: pycompat: implement a shlexquote that properly handles bytes

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Oct 8 04:43:00 UTC 2019


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  2cc453284d5 <https://phab.mercurial-scm.org/rHG2cc453284d5c473dc722c1cca1d4ea403fc5ebd2> introduced this function call to for mail.py. This broke Python
  3 because shlex.quote() expects str, not bytes. In order to unbust it,
  we need to normalize bytes to str then go back to bytes to appease the
  caller.
  
  This is a bit ugly. But I don't see any other obvious solution.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/pycompat.py

CHANGE DETAILS

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -337,7 +337,11 @@
         ret = shlex.split(s.decode('latin-1'), comments, posix)
         return [a.encode('latin-1') for a in ret]
 
-    shlexquote = shlex.quote
+    def shlexquote(s):
+        s = s.decode('latin-1')
+        s = shlex.quote(s)
+        return s.encode('latin-1')
+
     iteritems = lambda x: x.items()
     itervalues = lambda x: x.values()
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list