-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-111719: Add extra check for alias command #111720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -597,11 +597,20 @@ def precmd(self, line): | |||
args = line.split() | ||||
while args[0] in self.aliases: | ||||
line = self.aliases[args[0]] | ||||
ii = 1 | ||||
for tmpArg in args[1:]: | ||||
line = line.replace("%" + str(ii), | ||||
tmpArg) | ||||
ii += 1 | ||||
for idx in range(1, 10): | ||||
if f'%{idx}' in line: | ||||
if idx >= len(args): | ||||
self.error(f"Not enough arguments for alias '{args[0]}'") | ||||
# This is a no-op | ||||
return "!" | ||||
line = line.replace(f'%{idx}', args[idx]) | ||||
elif '%*' not in line: | ||||
if idx < len(args): | ||||
self.error(f"Too many arguments for alias '{args[0]}'") | ||||
# This is a no-op | ||||
return "!" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this return needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||||
break | ||||
|
||||
line = line.replace("%*", ' '.join(args[1:])) | ||||
args = line.split() | ||||
# split into ';;' separated commands | ||||
|
@@ -616,6 +625,7 @@ def precmd(self, line): | |||
|
||||
# Replace all the convenience variables | ||||
line = re.sub(r'\$([a-zA-Z_][a-zA-Z0-9_]*)', r'__pdb_convenience_variables["\1"]', line) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
return line | ||||
|
||||
def onecmd(self, line): | ||||
|
@@ -1797,7 +1807,18 @@ def do_alias(self, arg): | |||
else: | ||||
self.error(f"Unknown alias '{args[0]}'") | ||||
else: | ||||
self.aliases[args[0]] = ' '.join(args[1:]) | ||||
# Do a validation check to make sure no replaceable parameters | ||||
# are skipped if %* is not used. | ||||
alias = ' '.join(args[1:]) | ||||
if '%*' not in alias: | ||||
consecutive = True | ||||
for idx in range(1, 10): | ||||
if f'%{idx}' not in alias: | ||||
consecutive = False | ||||
if f'%{idx}' in alias and not consecutive: | ||||
self.error("Replaceable parameters must be consecutive") | ||||
return | ||||
self.aliases[args[0]] = alias | ||||
|
||||
def do_unalias(self, arg): | ||||
"""unalias name | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add extra argument validation for ``alias`` command in :mod:`pdb` |
Uh oh!
There was an error while loading. Please reload this page.