Skip to content

ConvertTo-Json allows Depth value of int.MaxValue but only supports maximum of 100 #15344

Description

@sdwheeler

See

/// <summary>
/// Gets or sets the Depth property.
/// </summary>
[Parameter]
[ValidateRange(0, int.MaxValue)]
public int Depth
{
get { return _depth; }
set { _depth = value; }
}

        /// <summary>
        /// Gets or sets the Depth property.
        /// </summary>
        [Parameter]
        [ValidateRange(0, int.MaxValue)]
        public int Depth
        {
            get { return _depth; }
            set { _depth = value; }
        }

The valid range should be 0 to 100, not int.MaxValue.

Steps to reproduce

PS C:\Git> dir | ConvertTo-Json -Depth 1000
ConvertTo-Json: The maximum depth allowed for serialization is 100.

Expected behavior

The error should come from parameter validation, not from BeginProcessing().

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hacktoberfest-AcceptedAccepted to participate in HacktoberfestIssue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions