From ad712c4b80f411fa0976d713efd2ff21d0674384 Mon Sep 17 00:00:00 2001 From: SERY Julien <145333959+jserygit@users.noreply.github.com> Date: Fri, 22 May 2026 23:34:26 +0200 Subject: [PATCH 1/2] Add validation to prevent alias name and definition from being the same in NewAliasCommand and SetAliasCommand --- .../commands/utility/NewAliasCommand.cs | 10 ++++++++++ .../commands/utility/SetAliasCommand.cs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs index 8ae43a6e4fd..f789ddc5bb6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Management.Automation; using System.Management.Automation.Internal; @@ -82,6 +83,15 @@ protected override void ProcessRecord() AliasInfo result = null; + if (string.Equals(newAlias.Name, newAlias.Definition, StringComparison.OrdinalIgnoreCase)) + { + PSArgumentException e = PSTraceSource.NewArgumentException("Value", NewObjectStrings.InvalidValue, newAlias.Name); + WriteError( + new ErrorRecord( + e.ErrorRecord, + e)); + return; + } try { if (string.IsNullOrEmpty(Scope)) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs index 6c0007fa2a2..23a40e99515 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Management.Automation; using System.Management.Automation.Internal; @@ -42,6 +43,15 @@ protected override void ProcessRecord() AliasInfo result = null; + if (string.Equals(aliasToSet.Name, aliasToSet.Definition, StringComparison.OrdinalIgnoreCase)) + { + PSArgumentException e = PSTraceSource.NewArgumentException("Value", NewObjectStrings.InvalidValue, aliasToSet.Name); + WriteError( + new ErrorRecord( + e.ErrorRecord, + e)); + return; + } try { if (string.IsNullOrEmpty(Scope)) From aee0cf67551e95e85e39be5b206fba9a0d13f338 Mon Sep 17 00:00:00 2001 From: SERY Julien <145333959+jserygit@users.noreply.github.com> Date: Sat, 23 May 2026 01:44:11 +0200 Subject: [PATCH 2/2] Add blank line for improved readability in NewAliasCommand and SetAliasCommand --- .../commands/utility/NewAliasCommand.cs | 1 + .../commands/utility/SetAliasCommand.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs index f789ddc5bb6..3428b377da3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs @@ -92,6 +92,7 @@ protected override void ProcessRecord() e)); return; } + try { if (string.IsNullOrEmpty(Scope)) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs index 23a40e99515..2732f1a4381 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs @@ -52,6 +52,7 @@ protected override void ProcessRecord() e)); return; } + try { if (string.IsNullOrEmpty(Scope))