Skip to content

Commit

Permalink
Merge pull request #425 from gregsdennis/pointer/indexoutofrange-for-…
Browse files Browse the repository at this point in the history
…array

jsonpointer - index out of range for array
  • Loading branch information
gregsdennis committed Mar 30, 2023
2 parents ea67872 + cff52fd commit 59f2ff5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions JsonPointer.Tests/GithubTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Text.Json.Nodes;
using NUnit.Framework;

namespace Json.Pointer.Tests;

public class GithubTests
{
[Test]
public void Issue408_ArrayDerefThrowsIndexOutOfRange()
{
var pointer = JsonPointer.Parse("/");
var data = JsonNode.Parse("[]");

var success = pointer.TryEvaluate(data, out var array);

Assert.IsFalse(success);
Assert.IsNull(array);
}
}
1 change: 1 addition & 0 deletions JsonPointer/JsonPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public bool TryEvaluate(JsonNode? root, out JsonNode? result)
{
case JsonArray array:
segmentValue = segment.Value;
if (segmentValue == string.Empty) return false;
if (segmentValue == "0")
{
if (array.Count == 0) return false;
Expand Down
4 changes: 2 additions & 2 deletions JsonPointer/JsonPointer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>Json.Pointer</RootNamespace>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
<FileVersion>3.0.1.0</FileVersion>
<PackageId>JsonPointer.Net</PackageId>
<Authors>Greg Dennis</Authors>
<Product>JsonPointer.Net</Product>
Expand Down
4 changes: 4 additions & 0 deletions json-everything.net/wwwroot/md/release-notes/json-pointer.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [3.0.1](https://github.com/gregsdennis/json-everything/pull/425) {#release-pointer-3.0.1}

[#408](https://github.com/gregsdennis/json-everything/issues/408) - Fixed an issue where an empty string segment fails for array values. Thanks to [@mbj2011](https://github.com/mbj2011) for finding and reporting this.

# [3.0.0](https://github.com/gregsdennis/json-everything/pull/326) {#release-pointer-3.0.0}

Updated model to more correctly represent a basic JSON Pointer.
Expand Down

0 comments on commit 59f2ff5

Please sign in to comment.