Skip to content

Fix ValidateRange Max Depth Allowed - #16197

Merged
Dongbo Wang (daxian-dbw) merged 5 commits into
PowerShell:masterfrom
KevRitchie:patch-1
Oct 28, 2021
Merged

Dongbo Wang (daxian-dbw) merged 5 commits into
PowerShell:masterfrom
KevRitchie:patch-1

Conversation

@KevRitchie

@KevRitchie Kev Ritchie (KevRitchie) commented Oct 5, 2021 •

Copy link
Copy Markdown
Contributor

PR Summary

Replace int.MaxValue with 100 so that parameter validation works as expected.

Remove BeginProcessing method. No longer required to do a prerequisite check on Max Depth. Parameter Argument Validation now used.

Update Json Tests.

PR Context

Fixes #15344

PR Checklist

Replaced int.MaxValue with maxDepthAllowed so that parameter validation works as expected.
Set ValidateRange MaxDepth to 100 explicitly.
Remove MaximumAllowedDepthReached and check for ParameterArgumentValidationError instead.
@ghost

Deleted user (ghost) commented Oct 5, 2021 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

Remove BeginProcessing method as no longer needed for prerequisite checks.
@daxian-dbw

Copy link
Copy Markdown
Member

Steve Lee (@SteveL-MSFT) can you please take a quick look?

@iSazonov

Copy link
Copy Markdown
Collaborator

I wonder why do we change the check if we get right error message? Also see #3181 - I wonder about it too.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Oct 6, 2021 •

Copy link
Copy Markdown
Member

The documentation is already up-to-date;

Specifies how many levels of contained objects are included in the JSON representation. The value can be any number from 1 to 100. The default value is 2. ConvertTo-Json emits a warning if the number of levels in an input object exceeds this number.

Ilya (@iSazonov) This is to fix the incorrect validate range attribute. While after fixing that, there is no need for explicit check.

@iSazonov

Copy link
Copy Markdown
Collaborator

The documentation is already up-to-date;

Specifies how many levels of contained objects are included in the JSON representation. The value can be any number from 1 to 100. The default value is 2. ConvertTo-Json emits a warning if the number of levels in an input object exceeds this number.

Ilya (@iSazonov) This is to fix the incorrect validate range attribute. While after fixing that, there is no need for explicit check.

I had reverse logic to keep PowerShell custom error message. :-) No objections to have ValidateRange error message.

@daxian-dbw

Copy link
Copy Markdown
Member

The documentation is already up-to-date;

Actually, there is an inconsistency in the doc. -Depth supports argument 0, but the help content say from 1 to 100.
Sean Wheeler (@sdwheeler), shall we update the doc?

@sdwheeler

Sean Wheeler (sdwheeler) commented Oct 6, 2021 •

Copy link
Copy Markdown
Contributor

Dongbo Wang (@daxian-dbw) It supports a value of 0 but is it valid?

PS> get-date | convertto-json -Depth 0
ConvertTo-Json: Cannot validate argument on parameter 'Depth'. The 0 argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again.

The supported range should probably start at 1, not 0.

@daxian-dbw

Copy link
Copy Markdown
Member

Sean Wheeler (@sdwheeler) It works on 7.2.0-preview.9, so I guess there was a change that made this work at some point.

image

@sdwheeler

Copy link
Copy Markdown
Contributor

Dongbo Wang (@daxian-dbw) Ah, yeah. I think that was one of the things fixed. The docs for the cmdlet in 7.2 already list the range as 0..100.

@daxian-dbw

Copy link
Copy Markdown
Member

Right, the 7.2 doc has the right content. Thanks Sean Wheeler (@sdwheeler)!

Specifies how many levels of contained objects are included in the JSON representation. The value can be any number from 0 to 100. The default value is 2. ConvertTo-Json emits a warning if the number of levels in an input object exceeds this number.

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 01426b2 into PowerShell:master Oct 28, 2021
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 29, 2021
@ghost

Copy link
Copy Markdown

🎉v7.3.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants