Skip to content

Commit

Permalink
Pr/19379 (#1)
Browse files Browse the repository at this point in the history
* Remove FormObject.cs and FormObjectCollection.cs (PowerShell#19383)

* Exclude redundant parameter aliases from completion results (PowerShell#19382)

* Revert "Remove FormObject.cs and FormObjectCollection.cs (PowerShell#19383)" (PowerShell#19387)

This reverts commit 190c99a.

* Add the parameter `-RelativeBasePath` to `Resolve-Path` (PowerShell#19358)

* Fix a crash in the type inference code (PowerShell#19400)

* Remove GetResponseObject (PowerShell#19380)

* Add `-Environment` parameter to `Start-Process` (PowerShell#19374)

* Add `-Environment` parameter to `Start-Process`

* address codefactor

* fix test for Windows

* handle case where value is $null to remove env var

* change variables to make it more clear what the test is doing

* Add PoolNames variable group to compliance pipeline (PowerShell#19408)

* Improve package management acceptance tests by not going to the gallery (PowerShell#19412)

* Skip VT100 tests on Windows Server 2012R2 as console does not support it (PowerShell#19413)

* Update the `ICommandPredictor` interface to reduce boilerplate code from predictor implementation (PowerShell#19414)

* Enable type conversion of `AutomationNull` to `$null` for assignment (PowerShell#19415)

* Remove code related to `#requires -pssnapin` (PowerShell#19320)

* Support CTRL-C when reading data and connection hangs for `Invoke-RestMethod` and `Invoke-WebRequest` (PowerShell#19330)

* Update to the latest NOTICES file (PowerShell#19332)

* Update the cgmanifest (PowerShell#19459)

* WIP: Harden default command test. (PowerShell#19416)
  • Loading branch information
stevenebutler committed Apr 8, 2023
1 parent 79698f3 commit 1a6707d
Show file tree
Hide file tree
Showing 41 changed files with 821 additions and 531 deletions.
96 changes: 96 additions & 0 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ limitations under the License.

---------------------------------------------------------

Markdig.Signed 0.31.0 - BSD-2-Clause



Copyright (c) <year> <owner> . All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

---------------------------------------------------------

---------------------------------------------------------

Microsoft.ApplicationInsights 2.21.0 - MIT


Expand Down Expand Up @@ -218,6 +236,48 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------

Microsoft.CodeAnalysis.Common 4.5.0 - MIT


(c) Microsoft Corporation
Copyright (c) .NET Foundation and Contributors

MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---------------------------------------------------------

---------------------------------------------------------

Microsoft.CodeAnalysis.CSharp 4.5.0 - MIT


(c) Microsoft Corporation
Copyright (c) Microsoft Corporation
Copyright (c) .NET Foundation and Contributors
Copyright (c) Microsoft Corporation. Alle Rechte

MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---------------------------------------------------------

---------------------------------------------------------
Expand Down Expand Up @@ -3682,6 +3742,42 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------

System.ServiceModel.NetFramingBase 6.0.0-preview1.23060.3 - MIT


(c) Microsoft Corporation
Copyright (c) .NET Foundation and Contributors
Copyright (c) 2000-2014 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)

The MIT License (MIT)

Copyright (c) .NET Foundation and Contributors

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,26 @@ public SwitchParameter UseNewEnvironment

private SwitchParameter _UseNewEnvironment;

/// <summary>
/// Gets or sets the environment variables for the process.
/// </summary>
[Parameter]
public Hashtable Environment
{
get
{
return _environment;
}

set
{
_environment = value;
_isDefaultSetParameterSpecified = true;
}
}

private Hashtable _environment;

#endregion

#region overrides
Expand Down Expand Up @@ -1929,8 +1949,13 @@ protected override void BeginProcessing()
if (_UseNewEnvironment)
{
startInfo.EnvironmentVariables.Clear();
LoadEnvironmentVariable(startInfo, Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine));
LoadEnvironmentVariable(startInfo, Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User));
LoadEnvironmentVariable(startInfo, System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine));
LoadEnvironmentVariable(startInfo, System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User));
}

if (_environment != null)
{
LoadEnvironmentVariable(startInfo, _environment);
}

startInfo.WindowStyle = _windowstyle;
Expand Down Expand Up @@ -2176,13 +2201,20 @@ private static void LoadEnvironmentVariable(ProcessStartInfo startinfo, IDiction
processEnvironment.Remove(entry.Key.ToString());
}

if (entry.Key.ToString().Equals("PATH"))
if (entry.Value != null)
{
processEnvironment.Add(entry.Key.ToString(), Environment.GetEnvironmentVariable(entry.Key.ToString(), EnvironmentVariableTarget.Machine) + ";" + Environment.GetEnvironmentVariable(entry.Key.ToString(), EnvironmentVariableTarget.User));
}
else
{
processEnvironment.Add(entry.Key.ToString(), entry.Value.ToString());
if (entry.Key.ToString().Equals("PATH"))
{
#if UNIX
processEnvironment.Add(entry.Key.ToString(), entry.Value.ToString());
#else
processEnvironment.Add(entry.Key.ToString(), entry.Value.ToString() + Path.PathSeparator + System.Environment.GetEnvironmentVariable(entry.Key.ToString(), EnvironmentVariableTarget.Machine) + Path.PathSeparator + System.Environment.GetEnvironmentVariable(entry.Key.ToString(), EnvironmentVariableTarget.User));
#endif
}
else
{
processEnvironment.Add(entry.Key.ToString(), entry.Value.ToString());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ResolvePathCommand : CoreCommandWithCredentialsBase
/// </summary>
[Parameter(Position = 0, ParameterSetName = "Path",
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
[Parameter(Position = 0, ParameterSetName = "PathWithRelativeBase",
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string[] Path
{
get
Expand All @@ -40,6 +42,8 @@ public string[] Path
/// </summary>
[Parameter(ParameterSetName = "LiteralPath",
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
[Parameter(ParameterSetName = "LiteralPathWithRelativeBase",
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
[Alias("PSPath", "LP")]
public string[] LiteralPath
{
Expand All @@ -59,7 +63,8 @@ public string[] LiteralPath
/// Gets or sets the value that determines if the resolved path should
/// be resolved to its relative version.
/// </summary>
[Parameter()]
[Parameter(ParameterSetName = "Path")]
[Parameter(ParameterSetName = "LiteralPath")]
public SwitchParameter Relative
{
get
Expand All @@ -75,6 +80,25 @@ public SwitchParameter Relative

private SwitchParameter _relative;

/// <summary>
/// Gets or sets the path the resolved relative path should be based off.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "PathWithRelativeBase")]
[Parameter(Mandatory = true, ParameterSetName = "LiteralPathWithRelativeBase")]
public string RelativeBasePath
{
get
{
return _relativeBasePath;
}

set
{
_relative = true;
_relativeBasePath = value;
}
}

#endregion Parameters

#region parameter data
Expand All @@ -84,10 +108,68 @@ public SwitchParameter Relative
/// </summary>
private string[] _paths;

private PSDriveInfo _relativeDrive;
private string _relativeBasePath;

#endregion parameter data

#region Command code

/// <summary>
/// Finds the path and drive that should be used for relative path resolution
/// represents.
/// </summary>
protected override void BeginProcessing()
{
if (_relative)
{
if (!string.IsNullOrEmpty(RelativeBasePath))
{
try
{
_relativeBasePath = SessionState.Internal.Globber.GetProviderPath(RelativeBasePath, CmdletProviderContext, out _, out _relativeDrive);
}
catch (ProviderNotFoundException providerNotFound)
{
ThrowTerminatingError(
new ErrorRecord(
providerNotFound.ErrorRecord,
providerNotFound));
}
catch (DriveNotFoundException driveNotFound)
{
ThrowTerminatingError(
new ErrorRecord(
driveNotFound.ErrorRecord,
driveNotFound));
}
catch (ProviderInvocationException providerInvocation)
{
ThrowTerminatingError(
new ErrorRecord(
providerInvocation.ErrorRecord,
providerInvocation));
}
catch (NotSupportedException notSupported)
{
ThrowTerminatingError(
new ErrorRecord(notSupported, "ProviderIsNotNavigationCmdletProvider", ErrorCategory.InvalidArgument, RelativeBasePath));
}
catch (InvalidOperationException invalidOperation)
{
ThrowTerminatingError(
new ErrorRecord(invalidOperation, "InvalidHomeLocation", ErrorCategory.InvalidOperation, RelativeBasePath));
}

return;
}

_relativeDrive = SessionState.Path.CurrentLocation.Drive;
_relativeBasePath = SessionState.Path.CurrentLocation.ProviderPath;
return;
}
}

/// <summary>
/// Resolves the path containing glob characters to the PowerShell paths that it
/// represents.
Expand All @@ -109,10 +191,9 @@ protected override void ProcessRecord()
{
// When result path and base path is on different PSDrive
// (../)*path should not go beyond the root of base path
if (currentPath.Drive != SessionState.Path.CurrentLocation.Drive &&
SessionState.Path.CurrentLocation.Drive != null &&
!currentPath.ProviderPath.StartsWith(
SessionState.Path.CurrentLocation.Drive.Root, StringComparison.OrdinalIgnoreCase))
if (currentPath.Drive != _relativeDrive &&
_relativeDrive != null &&
!currentPath.ProviderPath.StartsWith(_relativeDrive.Root, StringComparison.OrdinalIgnoreCase))
{
WriteObject(currentPath.Path, enumerateCollection: false);
continue;
Expand All @@ -127,8 +208,7 @@ protected override void ProcessRecord()
}

baseCache = basePath;
string adjustedPath = SessionState.Path.NormalizeRelativePath(currentPath.Path,
SessionState.Path.CurrentLocation.ProviderPath);
string adjustedPath = SessionState.Path.NormalizeRelativePath(currentPath.Path, _relativeBasePath);

// Do not insert './' if result path is not relative
if (!adjustedPath.StartsWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Microsoft.PowerShell.Commands
{
Expand All @@ -21,18 +22,20 @@ public class BasicHtmlWebResponseObject : WebResponseObject
/// <summary>
/// Initializes a new instance of the <see cref="BasicHtmlWebResponseObject"/> class.
/// </summary>
/// <param name="response"></param>
public BasicHtmlWebResponseObject(HttpResponseMessage response) : this(response, null) { }
/// <param name="response">The response.</param>
/// <param name="cancellationToken">Cancellation token.</param>
public BasicHtmlWebResponseObject(HttpResponseMessage response, CancellationToken cancellationToken) : this(response, null, cancellationToken) { }

/// <summary>
/// Initializes a new instance of the <see cref="BasicHtmlWebResponseObject"/> class
/// with the specified <paramref name="contentStream"/>.
/// </summary>
/// <param name="response"></param>
/// <param name="contentStream"></param>
public BasicHtmlWebResponseObject(HttpResponseMessage response, Stream contentStream) : base(response, contentStream)
/// <param name="response">The response.</param>
/// <param name="contentStream">The content stream associated with the response.</param>
/// <param name="cancellationToken">Cancellation token.</param>
public BasicHtmlWebResponseObject(HttpResponseMessage response, Stream contentStream, CancellationToken cancellationToken) : base(response, contentStream, cancellationToken)
{
InitializeContent();
InitializeContent(cancellationToken);
InitializeRawContent(response);
}

Expand Down Expand Up @@ -141,15 +144,16 @@ public WebCmdletElementCollection Images
/// <summary>
/// Reads the response content from the web response.
/// </summary>
protected void InitializeContent()
/// <param name="cancellationToken">The cancellation token.</param>
protected void InitializeContent(CancellationToken cancellationToken)
{
string contentType = ContentHelper.GetContentType(BaseResponse);
if (ContentHelper.IsText(contentType))
{
// Fill the Content buffer
string characterSet = WebResponseHelper.GetCharacterSet(BaseResponse);

Content = StreamHelper.DecodeStream(RawContentStream, characterSet, out Encoding encoding);
Content = StreamHelper.DecodeStream(RawContentStream, characterSet, out Encoding encoding, cancellationToken);
Encoding = encoding;
}
else
Expand Down
Loading

0 comments on commit 1a6707d

Please sign in to comment.