Skip to content

Commit 37ab85e

Browse files
committed
refactor(XMLDiff): improve replace attribute detection
1 parent 67153e9 commit 37ab85e

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

XMLDiff/Program.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private static bool CompareElements(
528528
{
529529
Logger.Debug($"Original attributes does not contain key '{attr.Key}'.");
530530
differencesInAttributesCount++;
531-
if (differencesInAttributesCount > 1 || modifiedAttributes.Count == 1)
531+
if (differencesInAttributesCount > 1)
532532
{
533533
differencesInAttributesCount++;
534534
matchedEnough = false;
@@ -544,7 +544,7 @@ private static bool CompareElements(
544544
$"Original attributes value '{originalAttributes[attr.Key]}' does not match with modified attributes value '{attr.Value}'."
545545
);
546546
differencesInAttributesCount++;
547-
if (differencesInAttributesCount > 1 || originalAttributes.Count == 1)
547+
if (differencesInAttributesCount > 1)
548548
{
549549
differencesInAttributesCount++;
550550
matchedEnough = false;
@@ -596,26 +596,19 @@ private static bool CompareElements(
596596
return true;
597597
}
598598
matchedEnough = false;
599-
if (!CompareElements(original, modified, diffRoot, pathOptions, originalChild, modifiedChild, true))
599+
if (
600+
!CompareElements(original, modified, diffRoot, pathOptions, originalChild, modifiedChild, true)
601+
&& originalChildren[i + 1].Name == modifiedChildren[j + 1].Name
602+
&& originalChildren[i + 1].Attributes().Count() == modifiedChildren[j + 1].Attributes().Count()
603+
&& originalChildren[i + 1].Attributes().All(attr => modifiedChildren[j + 1].Attribute(attr.Name)?.Value == attr.Value)
604+
)
600605
{
601-
bool nextMatched = true;
602-
if (i + 1 < originalChildren.Count && j + 1 < modifiedChildren.Count)
603-
{
604-
XElement originalTemp = new XElement("temp");
605-
originalTemp.Add(originalChildren[i + 1]);
606-
XElement modifiedTemp = new XElement("temp");
607-
modifiedTemp.Add(modifiedChildren[j + 1]);
608-
nextMatched = !CompareElements(original, modified, diffRoot, pathOptions, originalTemp, modifiedTemp, true);
609-
}
610-
if (nextMatched)
606+
if (savedOp != null)
611607
{
612-
if (savedOp != null)
613-
{
614-
diffRoot.Add(savedOp);
615-
Logger.Info($"[Operation {savedOp.Name}] Added the saved operation to the diff.");
616-
}
617-
matchedEnough = true;
608+
diffRoot.Add(savedOp);
609+
Logger.Info($"[Operation {savedOp.Name}] Added the saved operation to the diff.");
618610
}
611+
matchedEnough = true;
619612
}
620613
}
621614
Logger.Debug($"Matched enough: {matchedEnough}, i: {i}, j: {j}");

0 commit comments

Comments
 (0)