GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet
    • JsonObject.cs
  • test/powershell/Modules/Microsoft.PowerShell.Utility
    • ConvertFrom-Json.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs‎

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 numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ public static object ConvertFromJson(string input, bool returnHashtable, out Err
5959
error = null;
6060
try
6161
{
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-
7862
var obj = JsonConvert.DeserializeObject(
7963
input,
8064
new JsonSerializerSettings
Collapse file

‎test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertFrom-Json.Tests.ps1‎

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 numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ Describe 'ConvertFrom-Json' -tags "CI" {
5252
$json | Should -BeOfType Hashtable
5353
}
5454
}
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+
}
5561
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.