Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValidateRange Max Depth Allowed #16197

Merged
merged 5 commits into from
Oct 28, 2021
Merged

Conversation

KevRitchie
Copy link
Contributor

@KevRitchie KevRitchie commented Oct 5, 2021

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.
@ghost ghost assigned daxian-dbw Oct 5, 2021
Set ValidateRange MaxDepth to 100 explicitly.
Remove MaximumAllowedDepthReached and check for ParameterArgumentValidationError instead.
@ghost
Copy link

ghost commented Oct 5, 2021

CLA assistant check
All CLA requirements met.

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

@SteveL-MSFT can you please take a quick look?

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 6, 2021

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

@daxian-dbw
Copy link
Member

daxian-dbw commented Oct 6, 2021

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.

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

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 6, 2021

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.

@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
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.
@sdwheeler, shall we update the doc?

@sdwheeler
Copy link
Collaborator

sdwheeler commented Oct 6, 2021

@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
Member

@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
Collaborator

@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
Member

Right, the 7.2 doc has the right content. Thanks @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 daxian-dbw merged commit 01426b2 into PowerShell:master Oct 28, 2021
@iSazonov 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

ghost commented Dec 16, 2021

🎉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