NRE in CommandSearcher.GetNextCmdlet#12659
Merged
4 commits merged intoPowerShell:masterfrom May 19, 2020
Merged
Conversation
Collaborator
Author
|
@SteveL-MSFT Can you review? Didn't you add the abbreviation feature? |
PoshChan
reviewed
May 14, 2020
PoshChan
reviewed
May 14, 2020
PoshChan
reviewed
May 14, 2020
Collaborator
|
Repo steps: gcm a\b\get-qqq* -UseAbbreviationExpansion
Get-Command: Object reference not set to an instance of an object. |
Collaborator
|
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))) |
Member
|
@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
PoshChan
reviewed
May 18, 2020
PoshChan
reviewed
May 18, 2020
PoshChan
reviewed
May 18, 2020
PoshChan
reviewed
May 19, 2020
PoshChan
reviewed
May 19, 2020
PoshChan
reviewed
May 19, 2020
e70700b to
fe84eaa
Compare
iSazonov
reviewed
May 19, 2020
Functionallity wise equivalent but easier to read.
iSazonov
approved these changes
May 19, 2020
|
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: |
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.