Patchwork D2472: pycompat: prevent encoding or decoding values if not required

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 7:30 p.m.
Message ID <151ee570111941a8035c8bdc735403d0@localhost.localdomain>
Download mbox | patch
Permalink /patch/28806/
State Not Applicable
Headers show

Comments

phabricator - March 3, 2018, 7:30 p.m.
durin42 updated this revision to Diff 6449.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2472?vs=6439&id=6449

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

AFFECTED FILES
  mercurial/pycompat.py

CHANGE DETAILS




To: pulkit, #hg-reviewers, yuja, durin42
Cc: durin42, indygreg, yuja, mercurial-devel

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -192,11 +192,15 @@ 
 
     def strurl(url):
         """Converts a bytes url back to str"""
-        return url.decode(u'ascii')
+        if isinstance(url, bytes):
+            return url.decode(u'ascii')
+        return url
 
     def bytesurl(url):
         """Converts a str url to bytes by encoding in ascii"""
-        return url.encode(u'ascii')
+        if isinstance(url, str):
+            return url.encode(u'ascii')
+        return url
 
     def raisewithtb(exc, tb):
         """Raise exception with the given traceback"""