revset: drop redundant check for unknown alias arguments

Since _parsealiasdefn() rejects unknown alias arguments, _checkaliasarg() is
unnecessary. New test is added to make sure unknown '$n' symbols are rejected.
This commit is contained in:
Yuya Nishihara 2016-02-14 20:27:08 +09:00
parent 208bb924ba
commit 6c870f3b69
2 changed files with 9 additions and 13 deletions

View File

@ -2267,17 +2267,6 @@ def _getaliasarg(tree):
return tree[1] return tree[1]
return None return None
def _checkaliasarg(tree, known=None):
"""Check tree contains no _aliasarg construct or only ones which
value is in known. Used to avoid alias placeholders injection.
"""
if isinstance(tree, tuple):
arg = _getaliasarg(tree)
if arg is not None and (not known or arg not in known):
raise error.UnknownIdentifier('_aliasarg', [])
for t in tree:
_checkaliasarg(t, known)
# the set of valid characters for the initial letter of symbols in # the set of valid characters for the initial letter of symbols in
# alias declarations and definitions # alias declarations and definitions
_aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
@ -2443,8 +2432,6 @@ class revsetalias(object):
try: try:
self.replacement = _parsealiasdefn(value, self.args) self.replacement = _parsealiasdefn(value, self.args)
# Check for placeholder injection
_checkaliasarg(self.replacement, self.args)
except error.ParseError as inst: except error.ParseError as inst:
self.error = _('failed to parse the definition of revset alias' self.error = _('failed to parse the definition of revset alias'
' "%s": %s') % (self.name, parseerrordetail(inst)) ' "%s": %s') % (self.name, parseerrordetail(inst))

View File

@ -1820,6 +1820,15 @@ but 'all()' should never be substituded to '0()'.
<spanset+ 0:9>> <spanset+ 0:9>>
0 0
test unknown reference:
$ try "unknownref(0)" --config 'revsetalias.unknownref($1)=$1:$2'
(func
('symbol', 'unknownref')
('symbol', '0'))
abort: failed to parse the definition of revset alias "unknownref": '$' not for alias arguments
[255]
$ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip"
('symbol', 'tip') ('symbol', 'tip')
warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end