From 01426b276337b455fab79d0657a439658634f9a4 Mon Sep 17 00:00:00 2001
From: Kev Ritchie <65573253+KevRitchie@users.noreply.github.com>
Date: Thu, 28 Oct 2021 19:56:55 +0100
Subject: [PATCH] Fix `ConvertTo-Json -Depth` to allow 100 at maximum (#16197)
---
.../utility/WebCmdlet/ConvertToJsonCommand.cs | 22 ++-----------------
.../resources/WebCmdletStrings.resx | 3 ---
.../Json.Tests.ps1 | 4 ++--
3 files changed, 4 insertions(+), 25 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
index 36e8acdfd6..2e33a10096 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
@@ -27,15 +27,13 @@ namespace Microsoft.PowerShell.Commands
private int _depth = 2;
- private const int maxDepthAllowed = 100;
-
private readonly CancellationTokenSource _cancellationSource = new();
///
/// Gets or sets the Depth property.
///
[Parameter]
- [ValidateRange(0, int.MaxValue)]
+ [ValidateRange(0, 100)]
public int Depth
{
get { return _depth; }
@@ -99,23 +97,7 @@ namespace Microsoft.PowerShell.Commands
_cancellationSource.Dispose();
}
}
-
- ///
- /// Prerequisite checks.
- ///
- protected override void BeginProcessing()
- {
- if (_depth > maxDepthAllowed)
- {
- string errorMessage = StringUtil.Format(WebCmdletStrings.ReachedMaximumDepthAllowed, maxDepthAllowed);
- ThrowTerminatingError(new ErrorRecord(
- new InvalidOperationException(errorMessage),
- "ReachedMaximumDepthAllowed",
- ErrorCategory.InvalidOperation,
- null));
- }
- }
-
+
private readonly List