Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 74b5c22

Browse files
committed
Merge pull request #2154 from krwq/XPathWin10
Fix XPath tests to run on Desktop
2 parents f3a7195 + 9b6d7e3 commit 74b5c22

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/Common/src/System/Xml/Ref.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ internal static class Ref
1010
{
1111
public static bool Equal(string strA, string strB)
1212
{
13-
#if DEBUG
14-
if (((object)strA != (object)strB) && string.Equals(strA, strB))
15-
System.Diagnostics.Debug.Fail("Ref.Equal: Object comparison used for non-atomized string '" + strA + "'");
16-
#endif
17-
return (object)strA == (object)strB;
13+
// Active Issue: #2152
14+
return strA == strB;
1815
}
1916

2017
// Prevent typos. If someone uses Ref.Equals instead of Ref.Equal,

src/System.Xml.XPath.XDocument/tests/XDocument/NavigatorComparer.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ private static void CompareNavigators(XPathNavigator a, XPathNavigator b)
2929

3030
if (AreComparableNodes(a.NodeType, b.NodeType))
3131
{
32-
Assert.Equal(a.Value, b.Value);
33-
Assert.Equal(a.Value, b.Value);
32+
CompareValues(a, b);
3433
Assert.Equal(a.Name, b.Name);
3534
}
3635
#endif
@@ -69,6 +68,15 @@ private static void CompareNodeTypes(XPathNodeType a, XPathNodeType b)
6968
Assert.Equal(a, b);
7069
}
7170
}
71+
72+
private static void CompareValues(XPathNavigator a, XPathNavigator b)
73+
{
74+
// In order to account for Desktop vs CoreCLR difference in implementation of XmlDocument we need to normalize line endings to conform XML specification.
75+
string sa = a.Value.Replace("\r\n", "\n").Replace("\r", "\n");
76+
string sb = b.Value.Replace("\r\n", "\n").Replace("\r", "\n");
77+
78+
Assert.Equal(sa, sb);
79+
}
7280

7381
public NavigatorComparer(XPathNavigator nav1, XPathNavigator nav2)
7482
{
@@ -620,18 +628,16 @@ public override string Value
620628
{
621629
get
622630
{
623-
var r1 = _nav1.Value;
624-
var r2 = _nav2.Value;
625631
#if CHECK_ATTRIBUTE_ORDER
626-
Assert.Equal(r1, r2);
632+
CompareValues(_nav1, _nav2);
627633
#else
628634
CompareNodeTypes(_nav1.NodeType, _nav2.NodeType);
629635
if (!IsNamespaceOrAttribute(_nav1.NodeType))
630636
{
631-
Assert.Equal(r1, r2);
637+
CompareValues(_nav1, _nav2);
632638
}
633639
#endif
634-
return r1;
640+
return _nav1.Value;
635641
}
636642
}
637643
public override object ValueAs(Type value)

0 commit comments

Comments
 (0)