KirillOsenkov / XmlParser

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service
Apache License 2.0
328 stars 49 forks source link

Inconsistent results when parsing element with missing end tag. #63

Open grokys opened 2 months ago

grokys commented 2 months ago

Consider the following test:

[Theory]
[InlineData("<X><a><</X>")]
[InlineData("<X><a></</X>")]
public void IncompleteEndTag(string xml)
{
    var document = T(xml);
    var element = Assert.IsType<XmlElementSyntax>(document.Root.Elements.Single());
    Assert.Equal("a", element.StartTag.Name);
    Assert.Equal("", element.EndTag.Name);
}

In the first case ("<X><a><</X>") the test passes and element.EndTag.Name == "" however in the second case ("<X><a></</X>") the test fails because element.EndTag.Name == null.

It feels like this inconsistency is accidental, should it be normalized?

KirillOsenkov commented 2 months ago

I think it's purely accidental, we should normalize. Seems like an empty string is better than null.