Patchwork [2,of,3,STABLE,v2] py3: decode encoding literal before passing to .decode()

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 25, 2019, 12:53 p.m.
Message ID <5da37487d2dbd296d1ff.1572008034@steppe.local>
Download mbox | patch
Permalink /patch/42590/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 25, 2019, 12:53 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1571920100 -7200
#      Thu Oct 24 14:28:20 2019 +0200
# Branch stable
# Node ID 5da37487d2dbd296d1ffa79d9b99a1b4ab077335
# Parent  4ed5932bd9a54928a92156ac0252ce97965e6987
py3: decode encoding literal before passing to .decode()

bytes.decode(<encoding>) wants an str as "encoding" parameter,
it raises a TypeError if given a bytestring. encoding.encoding and
encoding.fallbackencoding are bytes values.

Patch

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -342,6 +342,7 @@  def _encode(ui, s, charsets):
         s.decode('ascii')
     except UnicodeDecodeError:
         for ics in (encoding.encoding, encoding.fallbackencoding):
+            ics = pycompat.sysstr(ics)
             try:
                 u = s.decode(ics)
             except UnicodeDecodeError: