From 81244c0ffe2f1c9d06ac0daf4becb17368ca5c3e Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Wed, 12 Oct 2016 10:02:27 -0700 Subject: [PATCH 1/2] Ignore whitespace text nodes when parsing projects This just ignores purely whitespace text nodes which seem to be part of the parsing in .NET Core and newer versions of System.Xml Closes #270, fixes test failures in #1004 --- .../UnitTests/Construction/ElementLocation_Tests.cs | 8 -------- src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/XMakeBuildEngine/UnitTests/Construction/ElementLocation_Tests.cs b/src/XMakeBuildEngine/UnitTests/Construction/ElementLocation_Tests.cs index 2ed1a695026..6dcc3cc7962 100644 --- a/src/XMakeBuildEngine/UnitTests/Construction/ElementLocation_Tests.cs +++ b/src/XMakeBuildEngine/UnitTests/Construction/ElementLocation_Tests.cs @@ -103,11 +103,7 @@ public void Equality() /// Check it will use large element location when it should. /// Using file as BIZARRELY XmlTextReader+StringReader crops or trims. /// -#if RUNTIME_TYPE_NETCORE - [Fact(Skip = "https://github.com/Microsoft/msbuild/issues/270")] -#else [Fact] -#endif public void TestLargeElementLocationUsedLargeColumn() { string file = null; @@ -135,11 +131,7 @@ public void TestLargeElementLocationUsedLargeColumn() /// Check it will use large element location when it should. /// Using file as BIZARRELY XmlTextReader+StringReader crops or trims. /// -#if RUNTIME_TYPE_NETCORE - [Fact(Skip = "https://github.com/Microsoft/msbuild/issues/270")] -#else [Fact] -#endif public void TestLargeElementLocationUsedLargeLine() { string file = null; diff --git a/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs b/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs index 79a2b26cbc5..21c86d47a54 100644 --- a/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs +++ b/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs @@ -48,6 +48,13 @@ private static List GetChildElements(XmlElementWithLocat VerifyThrowProjectValidNamespace(childElement); children.Add(childElement); break; + case XmlNodeType.Text: + // Whitespace is read as a #text element so if the node is purely whitespace, just ignore it. + if (!String.IsNullOrWhiteSpace(child.InnerText) && throwForInvalidNodeTypes) + { + ThrowProjectInvalidChildElement(child.Name, element.Name, element.Location); + } + break; default: if (throwForInvalidNodeTypes) From 38ba1fad40baa6dc1cf6e155e4b763a90f4727ce Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Wed, 12 Oct 2016 10:29:06 -0700 Subject: [PATCH 2/2] Address comments --- src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs b/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs index 21c86d47a54..9a551bedffd 100644 --- a/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs +++ b/src/XMakeBuildEngine/Xml/ProjectXmlUtilities.cs @@ -48,15 +48,15 @@ private static List GetChildElements(XmlElementWithLocat VerifyThrowProjectValidNamespace(childElement); children.Add(childElement); break; - case XmlNodeType.Text: - // Whitespace is read as a #text element so if the node is purely whitespace, just ignore it. - if (!String.IsNullOrWhiteSpace(child.InnerText) && throwForInvalidNodeTypes) - { - ThrowProjectInvalidChildElement(child.Name, element.Name, element.Location); - } - break; default: + if (child.NodeType == XmlNodeType.Text && String.IsNullOrWhiteSpace(child.InnerText)) + { + // If the text is greather than 4k and only contains whitespace, the XML reader will assume it's a text node + // instead of ignoring it. Our call to String.IsNullOrWhiteSpace() can be a little slow if the text is + // large but this should be extremely rare. + break; + } if (throwForInvalidNodeTypes) { ThrowProjectInvalidChildElement(child.Name, element.Name, element.Location);