diff --git a/Core.Tests/Parser/CommentTestFixture.cs b/Core.Tests/Parser/CommentTestFixture.cs
new file mode 100644
index 0000000..67dded8
--- /dev/null
+++ b/Core.Tests/Parser/CommentTestFixture.cs
@@ -0,0 +1,57 @@
+using MonoDevelop.Xml.Analysis;
+using MonoDevelop.Xml.Dom;
+using MonoDevelop.Xml.Parser;
+using NUnit.Framework;
+
+namespace MonoDevelop.Xml.Tests.Parser
+{
+ [TestFixture]
+ public class CommentTestFixture
+ {
+ public virtual XmlRootState CreateRootState ()
+ {
+ return new XmlRootState ();
+ }
+
+ [TestCase ("", " text ")]
+ [TestCase ("", " < ")]
+ [TestCase ("", " ", " {
+ parser.AssertStateIs ();
+ });
+
+ var comment = result.doc.RootElement?.FirstChild as XComment;
+
+ Assert.IsNotNull (comment);
+ Assert.AreEqual (innerText, comment.InnerText);
+ }
+
+ [TestCase ("");
+
+ parser.AssertDiagnostics (
+ (XmlCoreDiagnostics.IncompleteEndComment, 10, 0)
+ );
+ }
+ }
+}
diff --git a/Core/Dom/XComment.cs b/Core/Dom/XComment.cs
index 44ccc52..83fe332 100644
--- a/Core/Dom/XComment.cs
+++ b/Core/Dom/XComment.cs
@@ -36,6 +36,17 @@ public XComment (TextSpan span) : base (span) {}
protected XComment () {}
protected override XObject NewInstance () { return new XComment (); }
+ public string InnerText { get; private set; } = "";
+
+ public void End (string text)
+ {
+ int startLen = "".Length;
+
+ InnerText = text;
+ Span = new TextSpan (Span.Start, startLen + text.Length + endLen);
+ }
+
public override string FriendlyPathRepresentation {
get { return ""; }
}
diff --git a/Core/Parser/XmlCommentState.cs b/Core/Parser/XmlCommentState.cs
index 528bb2f..554fb11 100644
--- a/Core/Parser/XmlCommentState.cs
+++ b/Core/Parser/XmlCommentState.cs
@@ -68,7 +68,11 @@ public class XmlCommentState : XmlParserState
}
} else {
// not any part of a '-->', so make sure matching is reset
+ if (context.StateTag == SINGLE_DASH)
+ context.KeywordBuilder.Append ('-');
+
context.StateTag = NOMATCH;
+ context.KeywordBuilder.Append (c);
}
return null;
@@ -76,8 +80,7 @@ public class XmlCommentState : XmlParserState
XmlParserState? EndAndPop ()
{
var comment = (XComment)context.Nodes.Pop ();
-
- comment.End (context.PositionAfterCurrentChar);
+ comment.End (context.KeywordBuilder.ToString());
if (context.BuildTree) {
((XContainer)context.Nodes.Peek ()).AddChildNode (comment);
}