Patchwork [4,of,5] mail: call s.decode('ascii') explicitly to see if s is an ascii bytes

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 12, 2018, 3:27 a.m.
Message ID <a160d88772ff1da51160.1534044441@mimosa>
Download mbox | patch
Permalink /patch/33689/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 12, 2018, 3:27 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1534043668 -32400
#      Sun Aug 12 12:14:28 2018 +0900
# Node ID a160d88772ff1da51160faa5cfdbd7ecdbcd07fa
# Parent  6f357c717fa658015f5fd9c1be8e1ad9633ecddf
mail: call s.decode('ascii') explicitly to see if s is an ascii bytes

Patch

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -312,7 +312,7 @@  def _addressencode(ui, name, addr, chars
     name = headencode(ui, name, charsets)
     try:
         acc, dom = addr.split('@')
-        acc = acc.encode('ascii')
+        acc.decode('ascii')
         dom = dom.decode(encoding.encoding).encode('idna')
         addr = '%s@%s' % (acc, dom)
     except UnicodeDecodeError:
@@ -320,7 +320,7 @@  def _addressencode(ui, name, addr, chars
     except ValueError:
         try:
             # too strict?
-            addr = addr.encode('ascii')
+            addr.decode('ascii')
         except UnicodeDecodeError:
             raise error.Abort(_('invalid local address: %s') % addr)
     return pycompat.bytesurl(