From 1c390a6c6264ab39e4921317dc8ac1d6ffee010b Mon Sep 17 00:00:00 2001 From: Artyom Baranovskiy Date: Tue, 5 Nov 2013 23:04:35 +0300 Subject: [PATCH] Prevent Default OutputFormatter from breaking leading xml comment - As some sites specify leading xml comment tag instead of doctype, xml comment tag should not be broken during parsing of any document - When the comment tag is like - simply render it's NodeValue as no more wrapping is required --- .../Core/OutputFormatters/FormatDefault.cs | 22 +++++++++++++++++++ source/CsQuery.Tests/Csquery.Tests.csproj | 1 + .../CsQuery/Output/OutputFormatterDefault.cs | 4 ++++ 3 files changed, 27 insertions(+) create mode 100644 source/CsQuery.Tests/Core/OutputFormatters/FormatDefault.cs diff --git a/source/CsQuery.Tests/Core/OutputFormatters/FormatDefault.cs b/source/CsQuery.Tests/Core/OutputFormatters/FormatDefault.cs new file mode 100644 index 00000000..384137df --- /dev/null +++ b/source/CsQuery.Tests/Core/OutputFormatters/FormatDefault.cs @@ -0,0 +1,22 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NUnit.Framework; +using Assert = NUnit.Framework.Assert; + +namespace CsQuery.Tests.Core.OutputFormatters_ +{ + [TestFixture, TestClass] + class FormatDefault + { + [Test, TestMethod] + public void RenderLeadingXmlTag() + { + const string XmlTag = @""; + + var formatter = new Output.FormatDefault(); + var comment = new CsQuery.Implementation.DomComment(XmlTag); + var actual = formatter.Render(comment); + + Assert.AreEqual(XmlTag, actual, "FormatDefault should not change leading xml tag."); + } + } +} diff --git a/source/CsQuery.Tests/Csquery.Tests.csproj b/source/CsQuery.Tests/Csquery.Tests.csproj index 4e435cc8..66f300d0 100644 --- a/source/CsQuery.Tests/Csquery.Tests.csproj +++ b/source/CsQuery.Tests/Csquery.Tests.csproj @@ -96,6 +96,7 @@ + diff --git a/source/CsQuery/Output/OutputFormatterDefault.cs b/source/CsQuery/Output/OutputFormatterDefault.cs index b4cb1dc9..6c948817 100644 --- a/source/CsQuery/Output/OutputFormatterDefault.cs +++ b/source/CsQuery/Output/OutputFormatterDefault.cs @@ -430,6 +430,10 @@ protected void RenderCommentNode(IDomObject element, TextWriter writer) { return; } + else if (element.NodeValue.StartsWith("")) + { + writer.Write(element.NodeValue); + } else { writer.Write("");