Skip to content
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

jsonpointer - index out of range for array #425

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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