Skip to content

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

Closed

Description

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

Activity

  1. added
    Needs-Triage
    on May 4, 2021
  2. added
    Issue-Bug
    Up-for-Grabs
    and removed
    Needs-Triage
    on May 4, 2021
  3. kvprasoon commented on May 16, 2021

    @kvprasoon
    Contributor

    Dongbo Wang (@daxian-dbw) Was this added to provide a proper and controlled error message than the default error from validate range ?
    If so correcting the document will be sufficient.

  4. added
    Hacktoberfest-Accepted
    and removed
    Up-for-Grabs
    on Jul 12, 2021
  5. KevRitchie commented on Oct 5, 2021

    @KevRitchie
    Contributor

    Steve Lee (@SteveL-MSFT) / Sean Wheeler (@sdwheeler), does this still need working on? I'm happy to help.

  6. daxian-dbw commented on Oct 5, 2021

    @daxian-dbw
    Member

    Kev Ritchie (@KevRitchie) Please go ahead submit a PR to update the ValidateRange. Thanks!

  7. ghost added
    Resolution-Fixed
    on Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hacktoberfest-AcceptedIssue-BugResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions