-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
NRE in CommandSearcher.GetNextCmdlet #12659
Conversation
@SteveL-MSFT Can you review? Didn't you add the abbreviation feature? |
Repo steps: gcm a\b\get-qqq* -UseAbbreviationExpansion
Get-Command: Object reference not set to an instance of an object. |
We could simplify the change: WildcardPattern cmdletMatcher = null;
if (PSSnapinQualifiedCommandName != null && PSSnapinQualifiedCommandName.ShortName != null)
{
cmdletMatcher =
WildcardPattern.Get(
PSSnapinQualifiedCommandName.ShortName,
WildcardOptions.IgnoreCase);
}
SessionStateInternal ss = _context.EngineSessionState;
foreach (List<CmdletInfo> cmdletList in ss.GetCmdletTable().Values)
{
foreach (CmdletInfo cmdlet in cmdletList)
{
if ((cmdletMatcher != null && cmdletMatcher.IsMatch(cmdlet.Name)) ||
(_commandResolutionOptions.HasFlag(SearchResolutionOptions.FuzzyMatch) &&
FuzzyMatcher.IsFuzzyMatch(cmdlet.Name, _commandName)))
{
if (string.IsNullOrEmpty(PSSnapinQualifiedCommandName?.PSSnapInName) ||
(PSSnapinQualifiedCommandName.PSSnapInName.Equals(
cmdlet.ModuleName, StringComparison.OrdinalIgnoreCase))) |
@powercode please have a look at failing tests |
…is true. This will result in NRE if we don't check for it.
c658f21
to
0cc26d9
Compare
e70700b
to
fe84eaa
Compare
Functionallity wise equivalent but easier to read.
Hello @iSazonov! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
🎉 Handy links: |
PR Summary
Fixes a NullReferenceException when searching for malformed cmdlet names
PR Context
In GetNextCmdlet, there is a check
i.e. the null check is only done if useAbbreviationExpansion is false.
Later on we reference PSSnapinQualifiedCommandName in anyway and get an NRE.
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.