mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Emit warning if ConvertTo-Json exceeds -Depth value (#13692)
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Describe "SecureString conversion tests" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$string = "ABCD"
|
||||
@@ -24,9 +28,8 @@ Describe "SecureString conversion tests" -Tags "CI" {
|
||||
}
|
||||
|
||||
It "can convert back from a secure string" {
|
||||
$secret = "abcd"
|
||||
$ss1 = ConvertTo-SecureString -AsPlainText -Force $secret
|
||||
$ss1 = ConvertTo-SecureString -AsPlainText -Force $string
|
||||
$ss2 = ConvertFrom-SecureString $ss1 | ConvertTo-SecureString
|
||||
$ss2 | ConvertFrom-SecureString -AsPlainText | Should -Be $secret
|
||||
$ss2 | ConvertFrom-SecureString -AsPlainText | Should -Be $string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,4 +1463,11 @@ Describe "Json Bug fixes" -Tags "Feature" {
|
||||
$result = "[1,","2,","3]" | ConvertFrom-Json
|
||||
$result.Count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'ConvertTo-Json will output warning if depth is exceeded.' {
|
||||
$a = @{ a = @{ b = @{ c = @{ d = 1 } } } }
|
||||
$json = $a | ConvertTo-Json -Depth 2 -WarningVariable warningMessage -WarningAction SilentlyContinue
|
||||
$json | Should -Not -BeNullOrEmpty
|
||||
$warningMessage | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user