Patchwork [5,of,7] py3: fix stringmatcher() to byte-stringify exception message

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 14, 2020, 2:13 p.m.
Message ID <18bb913c45acf3f8d1fc.1602684815@mimosa>
Download mbox | patch
Permalink /patch/47460/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 14, 2020, 2:13 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1602681048 -32400
#      Wed Oct 14 22:10:48 2020 +0900
# Node ID 18bb913c45acf3f8d1fcbc90e22853f8e5f8e767
# Parent  b6c30689b9fe9e5f53bceb7913c71ae98109c804
py3: fix stringmatcher() to byte-stringify exception message

Spotted while writing regexp variant of stringmatcher().

Patch

diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -361,7 +361,9 @@  def stringmatcher(pattern, casesensitive
                 flags = remod.I
             regex = remod.compile(pattern, flags)
         except remod.error as e:
-            raise error.ParseError(_(b'invalid regular expression: %s') % e)
+            raise error.ParseError(
+                _(b'invalid regular expression: %s') % forcebytestr(e)
+            )
         return kind, pattern, regex.search
     elif kind == b'literal':
         if casesensitive:
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1448,6 +1448,9 @@  test author
     (string '('))
   hg: parse error: invalid match pattern: (unbalanced parenthesis|missing \),.*) (re)
   [255]
+  $ log 'desc("re:(")'
+  hg: parse error: invalid regular expression: (unbalanced parenthesis|missing \),.*) (re)
+  [255]
   $ try 'grep("\bissue\d+")'
   (func
     (symbol 'grep')