Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent breaking leading xml tag #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions source/CsQuery.Tests/Core/OutputFormatters/FormatDefault.cs
Original file line number Diff line number Diff line change
@@ -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 = @"<?xml version=""1.0"" encoding=""UTF-8""?>";

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.");
}
}
}
1 change: 1 addition & 0 deletions source/CsQuery.Tests/Csquery.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Arrays.cs" />
<Compile Include="AssertEx.cs" />
<Compile Include="Core\Documents\MultipleDocs.cs" />
<Compile Include="Core\OutputFormatters\FormatDefault.cs" />
<Compile Include="Core\Dom\DomContainer.cs" />
<Compile Include="Core\Dom\InnerText.cs" />
<Compile Include="Core\Dom\DomText.cs" />
Expand Down
4 changes: 4 additions & 0 deletions source/CsQuery/Output/OutputFormatterDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ protected void RenderCommentNode(IDomObject element, TextWriter writer)
{
return;
}
else if (element.NodeValue.StartsWith("<?") && element.NodeValue.EndsWith("?>"))
{
writer.Write(element.NodeValue);
}
else
{
writer.Write("<!--" + element.NodeValue + "-->");
Expand Down