mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Throw if markup contains unescaped close tag
This commit is contained in:

committed by
Patrik Svensson

parent
31f117aed0
commit
decb887b0a
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user