Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Fix mhutch#26
Browse files Browse the repository at this point in the history
Ensure the diagnostic on unexpected < after an opening tag is covering the second <.
  • Loading branch information
KirillOsenkov committed Apr 16, 2021
1 parent 069f5fb commit f318f73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Core/Parser/XmlRootState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public override XmlParserState PushChar (char c, XmlParserContext context, ref s
context.Diagnostics?.LogError (
"Incomplete tag opening; encountered unexpected '<'.",
TextSpan.FromBounds (
context.Position - LengthFromOpenBracket (context) - 1,
context.Position - 1
context.Position + 1 - LengthFromOpenBracket (context),
context.Position + 1
)
);
context.StateTag = BRACKET;
Expand Down
13 changes: 12 additions & 1 deletion Tests/Parser/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,5 +462,16 @@ public void InvalidNameState ()
parser.Parse (docTxt);
parser.AssertErrorCount (2);
}
}

[Test]
public void TwoOpenAngles ()
{
var docTxt = "<<";
var parser = new XmlTreeParser (CreateRootState ());
parser.Parse (docTxt);
var diagnostic = parser.GetContext ().Diagnostics.Single ();
Assert.AreEqual (1, diagnostic.Span.Start);
Assert.AreEqual (1, diagnostic.Span.Length);
}
}
}
6 changes: 6 additions & 0 deletions Tests/Parser/TestXmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public static void Parse (this XmlParser parser, string doc, char trigger = '$',
}
}
Assert.AreEqual (asserts.Length, assertNo);

var diagnostics = context.Diagnostics;
foreach (var diagnostic in diagnostics) {
Assert.GreaterOrEqual (diagnostic.Span.Start, 0);
Assert.GreaterOrEqual (diagnostic.Span.Length, 0);
}
}

public static XObject PeekSpine (this XmlParser parser) => parser.GetContext ().Nodes.Peek ();
Expand Down

0 comments on commit f318f73

Please sign in to comment.