Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Core.Tests/Parser/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ public void BadClosingTag ()
result.AssertDiagnosticCount (2);
}

[Test]
public void MalformedSelfClosingTag ()
{
var parser = new XmlTreeParser (CreateRootState ());
var result = parser.Parse (@"<root / $>",

() => {
parser.AssertStateIs<XmlTagState> ();
});

parser.AssertDiagnostics (
(XmlCoreDiagnostics.MalformedSelfClosingTag, 7, 0)
);
}

[Test]
public void MismatchedElementNameWithNamespace ()
{
Expand Down
7 changes: 6 additions & 1 deletion Core/Parser/XmlTagState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class XmlTagState : XmlParserState

const int ATTEMPT_RECOVERY = 1;
const int RECOVERY_FOUND_WHITESPACE = 2;
const int MAYBE_SELF_CLOSING = 2;
const int MAYBE_SELF_CLOSING = 3;
const int FREE = 0;

readonly XmlAttributeState AttributeState;
Expand Down Expand Up @@ -139,6 +139,11 @@ public XmlTagState (XmlAttributeState attributeState, XmlNameState nameState)
return null;
}

if (context.StateTag == MAYBE_SELF_CLOSING) {
context.Diagnostics?.Add (XmlCoreDiagnostics.MalformedSelfClosingTag, context.Position, c);
return null;
}

if (context.StateTag == ATTEMPT_RECOVERY) {
if (XmlChar.IsWhitespace (c)) {
context.StateTag = RECOVERY_FOUND_WHITESPACE;
Expand Down