This commit is contained in:
Ryan Nowak 2018-10-31 13:59:20 -07:00
parent aeb5c578e7
commit 3b485909eb
3 changed files with 50 additions and 1 deletions

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using Microsoft.AspNetCore.JsonPatch.Adapters;
using Newtonsoft.Json.Serialization;
@ -56,6 +55,13 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
adapter = null;
return false;
}
// If we hit a null on an interior segment then we need to stop traversing.
if (next == null)
{
adapter = null;
return false;
}
target = next;
adapter = SelectAdapter(target);

View File

@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Dynamic;
using Microsoft.AspNetCore.JsonPatch.Exceptions;
using Xunit;
namespace Microsoft.AspNetCore.JsonPatch.IntegrationTests
@ -124,5 +126,30 @@ namespace Microsoft.AspNetCore.JsonPatch.IntegrationTests
Assert.Equal(newGuid, targetObject.GuidValue);
}
// https://github.com/aspnet/AspNetCore/issues/3634
[Fact]
public void Regression_AspNetCore3634()
{
// Assert
var document = new JsonPatchDocument();
document.Move("/Object", "/Object/goodbye");
dynamic @object = new ExpandoObject();
@object.hello = "world";
var target = new Regression_AspNetCore3634_Object();
target.Object = @object;
// Act
var ex = Assert.Throws<JsonPatchException>(() => document.ApplyTo(target));
// Assert
Assert.Equal("For operation 'move', the target location specified by path '/Object/goodbye' was not found.", ex.Message);
}
private class Regression_AspNetCore3634_Object
{
public dynamic Object { get; set; }
}
}
}

View File

@ -205,6 +205,22 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
Assert.IsType<PocoAdapter>(adapter);
}
[Fact]
public void Visit_NullInteriorTarget_ReturnsFalse()
{
// Arrange
var visitor = new ObjectVisitor(new ParsedPath("/States/0"), new DefaultContractResolver());
// Act
object target = new Class1() { States = null, };
var visitStatus = visitor.TryVisit(ref target, out var adapter, out var message);
// Assert
Assert.False(visitStatus);
Assert.Null(adapter);
Assert.Null(message);
}
[Fact]
public void Visit_NullTarget_ReturnsNullAdapter()
{