# HG changeset patch # User Yuya Nishihara # Date 2018-01-13 06:07:37 # Node ID 735f47b41521b272c623aec952bcff52538d5466 # Parent 3e394e0558d7a1e7908db02aea7913e227a2cb44 fileset: make it robust for bad function calls Before, it could crash or show cryptic message. diff --git a/mercurial/fileset.py b/mercurial/fileset.py --- a/mercurial/fileset.py +++ b/mercurial/fileset.py @@ -99,6 +99,11 @@ def parse(expr): raise error.ParseError(_("invalid token"), pos) return tree +def getsymbol(x): + if x and x[0] == 'symbol': + return x[1] + raise error.ParseError(_('not a symbol')) + def getstring(x, err): if x and (x[0] == 'string' or x[0] == 'symbol'): return x[1] @@ -225,8 +230,8 @@ def clean(mctx, x): return [f for f in mctx.subset if f in s] def func(mctx, a, b): - if a[0] == 'symbol' and a[1] in symbols: - funcname = a[1] + funcname = getsymbol(a) + if funcname in symbols: enabled = mctx._existingenabled mctx._existingenabled = funcname in _existingcallers try: @@ -237,7 +242,7 @@ def func(mctx, a, b): keep = lambda fn: getattr(fn, '__doc__', None) is not None syms = [s for (s, fn) in symbols.items() if keep(fn)] - raise error.UnknownIdentifier(a[1], syms) + raise error.UnknownIdentifier(funcname, syms) def getlist(x): if not x: diff --git a/mercurial/minifileset.py b/mercurial/minifileset.py --- a/mercurial/minifileset.py +++ b/mercurial/minifileset.py @@ -56,9 +56,8 @@ def _compile(tree): 'size': lambda n, s: fileset.sizematcher(tree[2])(s), } - x = tree[1] - name = x[1] - if x[0] == 'symbol' and name in symbols: + name = fileset.getsymbol(tree[1]) + if name in symbols: return symbols[name] raise error.UnknownIdentifier(name, symbols.keys()) diff --git a/tests/test-fileset.t b/tests/test-fileset.t --- a/tests/test-fileset.t +++ b/tests/test-fileset.t @@ -53,6 +53,22 @@ Test operators and basic patterns hg: parse error: invalid \x escape [255] +Test invalid syntax + + $ fileset -v '"added"()' + (func + (string 'added') + None) + hg: parse error: not a symbol + [255] + $ fileset -v '()()' + (func + (group + None) + None) + hg: parse error: not a symbol + [255] + Test files status $ rm a1