Fix use of Start-Process http://bing.com (#9793)

This commit is contained in:
Steve Lee
2019-06-04 14:36:12 -07:00
committed by Travis Plunk
parent f222a686c5
commit b4e2423fab
2 changed files with 70 additions and 4 deletions
@@ -460,7 +460,7 @@ namespace System.Management.Automation
// Try literal path resolution if it is set to run first
if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns))
{
var path = GetNextLiteralPathThatExists(_commandName, out _);
var path = GetNextLiteralPathThatExistsAndHandleExceptions(_commandName, out _);
if (path != null)
{
@@ -478,7 +478,7 @@ namespace System.Management.Automation
if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) &&
resolvedPaths.Count == 0)
{
string path = GetNextLiteralPathThatExists(_commandName, out _);
string path = GetNextLiteralPathThatExistsAndHandleExceptions(_commandName, out _);
if (path != null)
{
@@ -1222,6 +1222,68 @@ namespace System.Management.Automation
return result;
}
/// <summary>
/// Gets the next literal path.
/// Filtering to ones that exist for the filesystem.
/// Handles Exceptions
/// </summary>
/// <param name="command">
/// The command to search for.
/// </param>
/// <param name="provider">The provider that the command was found in.</param>
/// <returns>
/// Full path to the command.
/// </returns>
private string GetNextLiteralPathThatExistsAndHandleExceptions(string command, out ProviderInfo provider)
{
try
{
return GetNextLiteralPathThatExists(command, out provider);
}
catch (ItemNotFoundException)
{
CommandDiscovery.discoveryTracer.TraceError(
"The path could not be found: {0}",
_commandName);
}
catch (DriveNotFoundException)
{
// This can be because we think a scope or a url is a drive
// and need to continue searching.
// Although, scope does not work through get-command
CommandDiscovery.discoveryTracer.TraceError(
"A drive could not be found for the path: {0}",
_commandName);
}
catch (ProviderNotFoundException)
{
CommandDiscovery.discoveryTracer.TraceError(
"A provider could not be found for the path: {0}",
_commandName);
}
catch (InvalidOperationException)
{
CommandDiscovery.discoveryTracer.TraceError(
"The path specified a home directory, but the provider home directory was not set. {0}",
_commandName);
}
catch (ProviderInvocationException providerException)
{
CommandDiscovery.discoveryTracer.TraceError(
"The provider associated with the path '{0}' encountered an error: {1}",
_commandName,
providerException.Message);
}
catch (PSNotSupportedException)
{
CommandDiscovery.discoveryTracer.TraceError(
"The provider associated with the path '{0}' does not implement ContainerCmdletProvider",
_commandName);
}
provider = null;
return null;
}
/// <summary>
/// Gets the next literal path.