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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Feb. 2, 2015, 2:10 p.m.
Message ID <bc6894e487f19bc1a3b2.1422886248@feefifofum>
Download mbox | patch
Permalink /patch/7591/
State Accepted
Commit 8a215678083975b85fed011b38297134e497818f
Headers show

Comments

Katsunori FUJIWARA - Feb. 2, 2015, 2:10 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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.
Matt Mackall - Feb. 2, 2015, 8:55 p.m.
On Mon, 2015-02-02 at 23:10 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@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

These are queued for default, thanks.

Patch

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