Throw if markup contains unescaped close tag

This commit is contained in:
Patrik Svensson
2020-08-26 21:15:52 +02:00
committed by Patrik Svensson
parent 31f117aed0
commit decb887b0a
2 changed files with 66 additions and 0 deletions

View File

@ -91,6 +91,8 @@ namespace Spectre.Console.Internal
{
var position = _reader.Position;
var builder = new StringBuilder();
var encounteredClosing = false;
while (!_reader.Eof)
{
current = _reader.Peek();
@ -98,10 +100,34 @@ namespace Spectre.Console.Internal
{
break;
}
else if (current == ']')
{
if (encounteredClosing)
{
_reader.Read();
encounteredClosing = false;
continue;
}
encounteredClosing = true;
}
else
{
if (encounteredClosing)
{
throw new InvalidOperationException(
$"Encountered unescaped ']' token at position {_reader.Position}");
}
}
builder.Append(_reader.Read());
}
if (encounteredClosing)
{
throw new InvalidOperationException($"Encountered unescaped ']' token at position {_reader.Position}");
}
Current = new MarkupToken(MarkupTokenKind.Text, builder.ToString(), position);
return true;
}