mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix completion crash for the SCCM provider (#20915)
This commit is contained in:
@@ -4878,10 +4878,22 @@ namespace System.Management.Automation
|
||||
|
||||
private static string GetChildNameFromPsObject(dynamic psObject, char separator)
|
||||
{
|
||||
// The obvious solution would be to use the "PSChildName" property
|
||||
// but some providers don't have it (like the Variable provider)
|
||||
// So we use a substring of "PSPath" instead.
|
||||
string childName = psObject.PSPath ?? string.Empty;
|
||||
if (((PSObject)psObject).BaseObject is string result)
|
||||
{
|
||||
// The "Get-ChildItem" call for this provider returned a string that we assume is the child name.
|
||||
// This is what the SCCM provider returns.
|
||||
return result;
|
||||
}
|
||||
|
||||
string childName = psObject.PSChildName;
|
||||
if (childName is not null)
|
||||
{
|
||||
return childName;
|
||||
}
|
||||
|
||||
// Some providers (Like the variable provider) don't include a PSChildName property
|
||||
// so we get the child name from the path instead.
|
||||
childName = psObject.PSPath ?? string.Empty;
|
||||
int ProviderSeparatorIndex = childName.IndexOf("::", StringComparison.Ordinal);
|
||||
childName = childName.Substring(ProviderSeparatorIndex + 2);
|
||||
int indexOfName = childName.LastIndexOf(separator);
|
||||
@@ -4892,7 +4904,7 @@ namespace System.Management.Automation
|
||||
|
||||
return childName.Substring(indexOfName + 1);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Takes a path and rebuilds it with the specified variable replacements.
|
||||
/// Also escapes special characters as needed.
|
||||
|
||||
Reference in New Issue
Block a user