diff --git a/JLio.Commands/Logic/CopyMove.cs b/JLio.Commands/Logic/CopyMove.cs index 632cfaf..b42c100 100644 --- a/JLio.Commands/Logic/CopyMove.cs +++ b/JLio.Commands/Logic/CopyMove.cs @@ -51,7 +51,7 @@ private int GetInnerArrayIndex() var toPath = JsonPathMethods.SplitPath(ToPath); if (!fromPath.HasArrayIndication || !toPath.HasArrayIndication) return -1; var index = fromPath.GetSameElementsIndex(toPath); - if (!HasArrayNotationAfterIndex(fromPath, index)) + if (!HasArrayNotationAfterIndex(fromPath, index) || index > 1) return index; return -1; diff --git a/JLio.UnitTests/CommandsTests/CopyMoveTests.cs b/JLio.UnitTests/CommandsTests/CopyMoveTests.cs index 6ebbe47..44baec7 100644 --- a/JLio.UnitTests/CommandsTests/CopyMoveTests.cs +++ b/JLio.UnitTests/CommandsTests/CopyMoveTests.cs @@ -146,6 +146,23 @@ public void CanCopyMovePropertiesInAnLayeredArray(string startobject, string mov expectedValue))); } + [TestCase( + "{\"firstArray\":[{\"target\":[],\"secondArray\":[{\"id\":\"item1\",\"sub\":{\"name\":\"item 1\"}},{\"id\":\"item2\",\"sub\":{\"name\":\"item 2\"}}]},{\"target\":[],\"secondArray\":[{\"id\":\"item3\",\"sub\":{\"name\":\"item 3\"}},{\"id\":\"item4\",\"sub\":{\"name\":\"item 4\"}}]}]}", + "$.firstArray[*].secondArray[*].sub", + "$.firstArray[*].target", + "{\"firstArray\":[{\"target\":[{\"name\":\"item 1\"},{\"name\":\"item 2\"}],\"secondArray\":[{\"id\":\"item1\",\"sub\":{\"name\":\"item 1\"}},{\"id\":\"item2\",\"sub\":{\"name\":\"item 2\"}}]},{\"target\":[{\"name\":\"item 3\"},{\"name\":\"item 4\"}],\"secondArray\":[{\"id\":\"item3\",\"sub\":{\"name\":\"item 3\"}},{\"id\":\"item4\",\"sub\":{\"name\":\"item 4\"}}]}]}" + )] + public void CanCopyPropertiesInAnLayeredArray(string startobject, string copyFrom, string copyTo, string expectedValue) + { + var startObject = startobject; + var result = + new Copy(copyFrom, copyTo).Execute( + JToken.Parse(startObject), executeOptions); + Assert.IsTrue(JToken.DeepEquals(result.Data, + JToken.Parse( + expectedValue))); + } + [Test] public void CanCopyMovePropertiesInAnArray() {