-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ConvertFrom-Json: Ignore comments inside array literals (#14553) #26050
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,6 +350,38 @@ c 3 | |
| $json | Should -BeOfType ([string]) | ||
| $json | Should -Be $Value.Substring(1, $Value.Length - 2) | ||
| } | ||
|
|
||
| It 'Ignores comments in arrays' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { | ||
| param($AsHashtable) | ||
|
|
||
| # https://github.com/powerShell/powerShell/issues/14553 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MatejKafka Please remove. We never use references to GitHub in tests.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think there is no harm to have this reference in test :)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useful if it were a tracking issue for a disabled test. In this form, it's just garbage. |
||
| '[ | ||
| // comment | ||
| 100, | ||
| /* comment */ | ||
| 200 | ||
| ]' | ConvertFrom-Json -AsHashtable:$AsHashtable | Should -Be @(100, 200) | ||
| } | ||
|
|
||
| It 'Ignores comments in dictionaries' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { | ||
| param($AsHashtable) | ||
|
|
||
| $json = '{ | ||
| // comment | ||
| "a": 100, | ||
| /* comment */ | ||
| "b": 200 | ||
| }' | ConvertFrom-Json -AsHashtable:$AsHashtable | ||
|
|
||
| if ($AsHashtable) { | ||
| $json.Keys | Should -Be @("a", "b") | ||
| } else { | ||
| $json.psobject.Properties | Should -HaveCount 2 | ||
| } | ||
|
|
||
| $json.a | Should -Be 100 | ||
| $json.b | Should -Be 200 | ||
| } | ||
| } | ||
|
|
||
| Describe 'ConvertFrom-Json -Depth Tests' -tags "Feature" { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daxian-dbw Just curious, why move
errorinitialization up here? Imo initializing it at the beginning can potentially hide issues where you forget to seterrorbeforereturn, while if it was only assigned directly before the return, compiler would throw an error about a potentially uninitialized variable.