revset: replace parsing alias definition by _parsealiasdefn to parse strictly
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 02 Feb 2015 23:07:04 +0900
changeset 23994 8a2156780839
parent 23993 eedade006458
child 23995 d8330fb8c44d
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.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Mon Feb 02 23:07:04 2015 +0900
+++ b/mercurial/revset.py	Mon Feb 02 23:07:04 2015 +0900
@@ -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:
--- a/tests/test-revset.t	Mon Feb 02 23:07:04 2015 +0900
+++ b/tests/test-revset.t	Mon Feb 02 23:07:04 2015 +0900
@@ -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