Skip to content

Commit

Permalink
Merge pull request #43310 from ravinperera00/issue_43091
Browse files Browse the repository at this point in the history
Fix exact equality bug when both values are xmlSequence singletons
  • Loading branch information
warunalakshitha authored Sep 18, 2024
2 parents 807de37 + 7d9ad3a commit 3dadeb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,21 @@ public static boolean isReferenceEqual(Object lhsValue, Object rhsValue) {
}

private static boolean isXMLValueRefEqual(XmlValue lhsValue, XmlValue rhsValue) {
if (lhsValue.getNodeType() == XmlNodeType.SEQUENCE && lhsValue.isSingleton()) {
boolean isLhsXmlSequence = lhsValue.getNodeType() == XmlNodeType.SEQUENCE;
boolean isRhsXmlSequence = rhsValue.getNodeType() == XmlNodeType.SEQUENCE;

if (isLhsXmlSequence && isRhsXmlSequence) {
return isXMLSequenceRefEqual((XmlSequence) lhsValue, (XmlSequence) rhsValue);
}
if (isLhsXmlSequence && lhsValue.isSingleton()) {
return ((XmlSequence) lhsValue).getChildrenList().get(0) == rhsValue;
}
if (rhsValue.getNodeType() == XmlNodeType.SEQUENCE && rhsValue.isSingleton()) {
if (isRhsXmlSequence && rhsValue.isSingleton()) {
return ((XmlSequence) rhsValue).getChildrenList().get(0) == lhsValue;
}
if (lhsValue.getNodeType() != rhsValue.getNodeType()) {
return false;
}
if (lhsValue.getNodeType() == XmlNodeType.SEQUENCE && rhsValue.getNodeType() == XmlNodeType.SEQUENCE) {
return isXMLSequenceRefEqual((XmlSequence) lhsValue, (XmlSequence) rhsValue);
}
if (lhsValue.getNodeType() == XmlNodeType.TEXT && rhsValue.getNodeType() == XmlNodeType.TEXT) {
return isEqual(lhsValue, rhsValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,11 @@ function testXMLSequenceRefEquality() {
xml x1 = xml `<b>b</b>`;
xml x2 = x + x1;
xml x3 = x + x1;
xml x4 = xml:concat(x);
xml x5 = xml:concat(x);

test:assertTrue(x2 === x3);
test:assertTrue(x4 === x5);

xml a1 = xml `<e1/>`;
xml a2 = xml `<e2/>`;
Expand Down

0 comments on commit 3dadeb5

Please sign in to comment.