[PATCH 2 of 2] revset: replace parsing alias definition by _parsealiasdefn to parse strictly

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Feb 2 08:10:48 CST 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1422886024 -32400
#      Mon Feb 02 23:07:04 2015 +0900
# Branch stable
# Node ID bc6894e487f19bc1a3b21c0ccfc2701d7a1889ba
# Parent  4d367cc389593ffa26c0f97afa69caf744497cdd
revset: replace parsing alias definition by _parsealiasdefn to parse strictly

Before this patch, referring alias arguments is parsed by string base
operation "str.replace".

This causes problems below (see the previous patch introducing
"_parsealiasdefn" for detail)

  - the shorter name argument breaks referring the longer name
  - argument names in the quoted string are broken

This patch replaces parsing alias definition by "_parsealiasdefn" to
parse strictly.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2324,16 +2324,8 @@
                            ' "%s": %s') % (self.name, self.error)
             return
 
-        if self.args:
-            for arg in self.args:
-                # _aliasarg() is an unknown symbol only used separate
-                # alias argument placeholders from regular strings.
-                value = value.replace(arg, '_aliasarg(%r)' % (arg,))
-
         try:
-            self.replacement, pos = parse(value)
-            if pos != len(value):
-                raise error.ParseError(_('invalid token'), pos)
+            self.replacement = _parsealiasdefn(value, self.args)
             # Check for placeholder injection
             _checkaliasarg(self.replacement, self.args)
         except error.ParseError, inst:
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1024,6 +1024,19 @@
   ('symbol', 'tip')
   warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token
   9
+  $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc
+  $ try 'strictreplacing("foo", tip)'
+  (func
+    ('symbol', 'strictreplacing')
+    (list
+      ('string', 'foo')
+      ('symbol', 'tip')))
+  (or
+    ('symbol', 'tip')
+    (func
+      ('symbol', 'desc')
+      ('string', '$1')))
+  9
 
   $ try 'd(2:5)'
   (func


More information about the Mercurial-devel mailing list