@@ -597,11 +597,20 @@ def precmd(self, line):
597597 args = line .split ()
598598 while args [0 ] in self .aliases :
599599 line = self .aliases [args [0 ]]
600- ii = 1
601- for tmpArg in args [1 :]:
602- line = line .replace ("%" + str (ii ),
603- tmpArg )
604- ii += 1
600+ for idx in range (1 , 10 ):
601+ if f'%{ idx } ' in line :
602+ if idx >= len (args ):
603+ self .error (f"Not enough arguments for alias '{ args [0 ]} '" )
604+ # This is a no-op
605+ return "!"
606+ line = line .replace (f'%{ idx } ' , args [idx ])
607+ elif '%*' not in line :
608+ if idx < len (args ):
609+ self .error (f"Too many arguments for alias '{ args [0 ]} '" )
610+ # This is a no-op
611+ return "!"
612+ break
613+
605614 line = line .replace ("%*" , ' ' .join (args [1 :]))
606615 args = line .split ()
607616 # split into ';;' separated commands
@@ -616,6 +625,7 @@ def precmd(self, line):
616625
617626 # Replace all the convenience variables
618627 line = re .sub (r'\$([a-zA-Z_][a-zA-Z0-9_]*)' , r'__pdb_convenience_variables["\1"]' , line )
628+
619629 return line
620630
621631 def onecmd (self , line ):
@@ -1797,7 +1807,18 @@ def do_alias(self, arg):
17971807 else :
17981808 self .error (f"Unknown alias '{ args [0 ]} '" )
17991809 else :
1800- self .aliases [args [0 ]] = ' ' .join (args [1 :])
1810+ # Do a validation check to make sure no replaceable parameters
1811+ # are skipped if %* is not used.
1812+ alias = ' ' .join (args [1 :])
1813+ if '%*' not in alias :
1814+ consecutive = True
1815+ for idx in range (1 , 10 ):
1816+ if f'%{ idx } ' not in alias :
1817+ consecutive = False
1818+ if f'%{ idx } ' in alias and not consecutive :
1819+ self .error ("Replaceable parameters must be consecutive" )
1820+ return
1821+ self .aliases [args [0 ]] = alias
18011822
18021823 def do_unalias (self , arg ):
18031824 """unalias name
0 commit comments