Skip to content

Commit 03b1999

Browse files
committed
GetMergedNestedText is affected by #38 as well
1 parent e987280 commit 03b1999

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
be compared.
77
Inspired by Issue [#xmlunit/259](https://github.com/xmlunit/xmlunit/issues/259)
88

9-
* `Nodes.StripElementContentWhitespace` had the same problem of not
10-
knowning about `XmlWhitespace` that caused
11-
Issue [#38](https://github.com/xmlunit/xmlunit.net/issues/38)
9+
* `Nodes.GetMergedNestedText` and
10+
`Nodes.StripElementContentWhitespace` had the same problem of not
11+
knowning about `XmlWhitespace` that caused Issue
12+
[#38](https://github.com/xmlunit/xmlunit.net/issues/38). And neither
13+
of the methods could deal with `XmlSignificantWhitespace` at all.
1214

1315
## XMLUnit.NET 2.9.2 - /Released 2023-03-16/
1416

src/main/net-core/Util/Nodes.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static XmlQualifiedName GetQName(this XmlNode n) {
4040
public static string GetMergedNestedText(XmlNode n) {
4141
return n.ChildNodes
4242
.Cast<XmlNode>()
43-
.Where(child => child is XmlText || child is XmlCDataSection)
43+
.Where(child => IsTextualContentNode(child))
4444
.Select(child => child.Value)
4545
.Where(s => s != null)
4646
.Aggregate(new StringBuilder(), (sb, s) => sb.Append(s))
@@ -147,7 +147,7 @@ private static void HandleWsRec(XmlNode n, bool normalize) {
147147
foreach (XmlNode child in n.ChildNodes) {
148148
HandleWsRec(child, normalize);
149149
if (!(n is XmlAttribute)
150-
&& (child is XmlText || child is XmlCDataSection || child is XmlWhitespace)
150+
&& IsTextualContentNode(child)
151151
&& child.Value.Length == 0) {
152152
toRemove.AddLast(child);
153153
}
@@ -199,7 +199,7 @@ private static void StripECW(XmlNode n) {
199199
foreach (XmlNode child in n.ChildNodes) {
200200
StripECW(child);
201201
if (!(n is XmlAttribute)
202-
&& (child is XmlText || child is XmlCDataSection || child is XmlWhitespace)
202+
&& IsTextualContentNode(child)
203203
&& child.Value.Trim().Length == 0) {
204204
toRemove.AddLast(child);
205205
}
@@ -208,5 +208,10 @@ private static void StripECW(XmlNode n) {
208208
n.RemoveChild(child);
209209
}
210210
}
211+
212+
private static bool IsTextualContentNode(XmlNode n) {
213+
return n is XmlText || n is XmlCDataSection || n is XmlWhitespace
214+
|| n is XmlSignificantWhitespace;
215+
}
211216
}
212217
}

0 commit comments

Comments
 (0)