mercurial/revset.py
changeset 28690 b56bf98c8afb
parent 28689 a14732e08fec
child 28691 a04baf9c063b
equal deleted inserted replaced
28689:a14732e08fec 28690:b56bf98c8afb
  2265     """If tree matches ('_aliasarg', X) return X, None otherwise"""
  2265     """If tree matches ('_aliasarg', X) return X, None otherwise"""
  2266     if tree[0] == '_aliasarg':
  2266     if tree[0] == '_aliasarg':
  2267         return tree[1]
  2267         return tree[1]
  2268     return None
  2268     return None
  2269 
  2269 
  2270 def _checkaliasarg(tree, known=None):
       
  2271     """Check tree contains no _aliasarg construct or only ones which
       
  2272     value is in known. Used to avoid alias placeholders injection.
       
  2273     """
       
  2274     if isinstance(tree, tuple):
       
  2275         arg = _getaliasarg(tree)
       
  2276         if arg is not None and (not known or arg not in known):
       
  2277             raise error.UnknownIdentifier('_aliasarg', [])
       
  2278         for t in tree:
       
  2279             _checkaliasarg(t, known)
       
  2280 
       
  2281 # the set of valid characters for the initial letter of symbols in
  2270 # the set of valid characters for the initial letter of symbols in
  2282 # alias declarations and definitions
  2271 # alias declarations and definitions
  2283 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
  2272 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
  2284                            if c.isalnum() or c in '._@$' or ord(c) > 127)
  2273                            if c.isalnum() or c in '._@$' or ord(c) > 127)
  2285 
  2274 
  2441                            ' "%s": %s') % (self.name, self.error)
  2430                            ' "%s": %s') % (self.name, self.error)
  2442             return
  2431             return
  2443 
  2432 
  2444         try:
  2433         try:
  2445             self.replacement = _parsealiasdefn(value, self.args)
  2434             self.replacement = _parsealiasdefn(value, self.args)
  2446             # Check for placeholder injection
       
  2447             _checkaliasarg(self.replacement, self.args)
       
  2448         except error.ParseError as inst:
  2435         except error.ParseError as inst:
  2449             self.error = _('failed to parse the definition of revset alias'
  2436             self.error = _('failed to parse the definition of revset alias'
  2450                            ' "%s": %s') % (self.name, parseerrordetail(inst))
  2437                            ' "%s": %s') % (self.name, parseerrordetail(inst))
  2451 
  2438 
  2452 def _getalias(aliases, tree):
  2439 def _getalias(aliases, tree):