From 3dc6a8cca4bb6e948e8adb205933ce486f67c288 Mon Sep 17 00:00:00 2001 From: Declan Bourke <83952189+declan-bourke@users.noreply.github.com> Date: Mon, 30 Jan 2023 07:16:10 +0000 Subject: [PATCH] Fixed memory leak bug caused by query list keyvaluepair variable params (#5718) --- .../src/Core/Internal/ComparisonHelper.cs | 8 ++++ .../test/Core.Tests/OperationRequestTests.cs | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/StrawberryShake/Client/src/Core/Internal/ComparisonHelper.cs b/src/StrawberryShake/Client/src/Core/Internal/ComparisonHelper.cs index b155112c460..715473d682e 100644 --- a/src/StrawberryShake/Client/src/Core/Internal/ComparisonHelper.cs +++ b/src/StrawberryShake/Client/src/Core/Internal/ComparisonHelper.cs @@ -171,6 +171,14 @@ private static bool ObjEqual(object? first, object? second) { return DictionaryEqualInternal(firstReadDict, secondReadDict); } + + if (first is IEnumerable> firstKvp && + second is IEnumerable> secondKvp) + { + return DictionaryEqualInternal( + firstKvp.ToDictionary(t => t.Key, t => t.Value), + secondKvp.ToDictionary(t => t.Key, t => t.Value)); + } if (first is not string && second is not string && diff --git a/src/StrawberryShake/Client/test/Core.Tests/OperationRequestTests.cs b/src/StrawberryShake/Client/test/Core.Tests/OperationRequestTests.cs index 095d0ebeb80..a86917ba6a1 100644 --- a/src/StrawberryShake/Client/test/Core.Tests/OperationRequestTests.cs +++ b/src/StrawberryShake/Client/test/Core.Tests/OperationRequestTests.cs @@ -551,6 +551,48 @@ public void Equals_With_Variables_JSON() Assert.True(a.Equals(b)); } + [Fact] + public void Equals_With_Variables_KeyValuePair() + { + // arrange + var document = new Mock(); + var a = new OperationRequest( + null, + "abc", + document.Object, + new Dictionary + { + { "a", new List> + { + new KeyValuePair("b", new List> + { + new KeyValuePair("id", "123456") + }) + } + } + }); + + var b = new OperationRequest( + null, + "abc", + document.Object, + new Dictionary + { + { "a", new List> + { + new KeyValuePair("b", new List> + { + new KeyValuePair("id", "123456") + }) + } + } + }); + + // act + // assert + Assert.True(a.Equals(b)); + } + [Fact] public void Equals_No_Variables() {