This commit is contained in:
parent
aeb5c578e7
commit
3b485909eb
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using Microsoft.AspNetCore.JsonPatch.Adapters;
|
using Microsoft.AspNetCore.JsonPatch.Adapters;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
|
@ -56,6 +55,13 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
|
||||||
adapter = null;
|
adapter = null;
|
||||||
return false;
|
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;
|
target = next;
|
||||||
adapter = SelectAdapter(target);
|
adapter = SelectAdapter(target);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Dynamic;
|
||||||
|
using Microsoft.AspNetCore.JsonPatch.Exceptions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.JsonPatch.IntegrationTests
|
namespace Microsoft.AspNetCore.JsonPatch.IntegrationTests
|
||||||
|
|
@ -124,5 +126,30 @@ namespace Microsoft.AspNetCore.JsonPatch.IntegrationTests
|
||||||
Assert.Equal(newGuid, targetObject.GuidValue);
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,22 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
|
||||||
Assert.IsType<PocoAdapter>(adapter);
|
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]
|
[Fact]
|
||||||
public void Visit_NullTarget_ReturnsNullAdapter()
|
public void Visit_NullTarget_ReturnsNullAdapter()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue