Skip to content

Fix ValidateRange Max Depth Allowed#16197

Merged
daxian-dbw merged 5 commits intoPowerShell:masterfrom
KevRitchie:patch-1
Oct 28, 2021
Merged

Fix ValidateRange Max Depth Allowed#16197
daxian-dbw merged 5 commits intoPowerShell:masterfrom
KevRitchie:patch-1

Conversation

@KevRitchie
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Member

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

@daxian-dbw daxian-dbw requested a review from SteveL-MSFT October 6, 2021 00:46
@iSazonov
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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.
@sdwheeler, shall we update the doc?

@sdwheeler
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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