Patchwork D2582: util: teach escapedata() about bytearray

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 2:53 p.m.
Message ID <differential-rev-PHID-DREV-yeqfgqehpyosasnhoek7-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28780/
State Superseded
Headers show

Comments

phabricator - March 3, 2018, 2:53 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  re.map doesn't seem to know about bytearray (at least in Python 2).
  Cast bytearray to a bytes to work around this inconvenience.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -702,6 +702,9 @@ 
 DATA_ESCAPE_RE = remod.compile(br'[\x00-\x08\x0a-\x1f\\\x7f-\xff]')
 
 def escapedata(s):
+    if isinstance(s, bytearray):
+        s = bytes(s)
+
     return DATA_ESCAPE_RE.sub(lambda m: DATA_ESCAPE_MAP[m.group(0)], s)
 
 class fileobjectobserver(object):