GeezerVison is showing github.com — Remove workaround for fixed invalid json array deserializing bug (#8346) · PowerShell/PowerShell@60a4e2f
File tree
Expand file treeCollapse file tree
Open diff view settings
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet test/powershell/Modules/Microsoft.PowerShell.Utility
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs -16Lines changed: 0 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,22 +59,6 @@ public static object ConvertFromJson(string input, bool returnHashtable, out Err |
59 | 59 | error = null; |
60 | 60 | try |
61 | 61 | { |
62 | | - // JsonConvert.DeserializeObject does not throw an exception when an invalid Json array is passed. |
63 | | - // This issue is being tracked by https://github.com/JamesNK/Newtonsoft.Json/issues/1321. |
64 | | - // To work around this, we need to identify when input is a Json array, and then try to parse it via JArray.Parse(). |
65 | | - |
66 | | - // If input starts with '[' (ignoring white spaces). |
67 | | - if (Regex.Match(input, @"^\s*\[").Success) |
68 | | - { |
69 | | - // JArray.Parse() will throw a JsonException if the array is invalid. |
70 | | - // This will be caught by the catch block below, and then throw an |
71 | | - // ArgumentException - this is done to have same behavior as the JavaScriptSerializer. |
72 | | - JArray.Parse(input); |
73 | | - |
74 | | - // Please note that if the Json array is valid, we don't do anything, |
75 | | - // we just continue the deserialization. |
76 | | - } |
77 | | - |
78 | 62 | var obj = JsonConvert.DeserializeObject( |
79 | 63 | input, |
80 | 64 | new JsonSerializerSettings |
|
Collapse file
Copy file name to clipboardExpand all lines: test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1 +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,4 +52,10 @@ Describe 'ConvertFrom-Json' -tags "CI" { |
52 | 52 | $json | Should -BeOfType Hashtable |
53 | 53 | } |
54 | 54 | } |
| 55 | + |
| 56 | + It 'Throws an ArgumentException with an incomplete array with AsHashtable switch set to <AsHashtable>' -TestCase $testCasesWithAndWithoutAsHashtableSwitch { |
| 57 | + Param($AsHashtable) |
| 58 | + { ConvertFrom-Json '["1",' -AsHashtable:$AsHashtable } | |
| 59 | + Should -Throw -ErrorId "System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand" |
| 60 | + } |
55 | 61 | } |