mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Modified MarkupTokenizer
So escaped markup in markup is valid.
This commit is contained in:
parent
638149f44b
commit
a6618f762c
@ -66,13 +66,39 @@ internal sealed class MarkupTokenizer : IDisposable
|
|||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
while (!_reader.Eof)
|
while (!_reader.Eof)
|
||||||
{
|
{
|
||||||
current = _reader.Peek();
|
current = _reader.Read();
|
||||||
|
var next = '\0';
|
||||||
|
if (!_reader.Eof)
|
||||||
|
{
|
||||||
|
next = _reader.Peek();
|
||||||
|
}
|
||||||
|
|
||||||
if (current == ']')
|
if (current == ']')
|
||||||
|
{
|
||||||
|
if (next != ']')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Append(_reader.Read());
|
_reader.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Append(current);
|
||||||
|
|
||||||
|
if (current != '[')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next == '[')
|
||||||
|
{
|
||||||
|
_reader.Read();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"Encountered malformed markup tag at position {_reader.Position - 1}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_reader.Eof)
|
if (_reader.Eof)
|
||||||
@ -80,7 +106,6 @@ internal sealed class MarkupTokenizer : IDisposable
|
|||||||
throw new InvalidOperationException($"Encountered malformed markup tag at position {_reader.Position}.");
|
throw new InvalidOperationException($"Encountered malformed markup tag at position {_reader.Position}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_reader.Read();
|
|
||||||
Current = new MarkupToken(MarkupTokenKind.Open, builder.ToString(), position);
|
Current = new MarkupToken(MarkupTokenKind.Open, builder.ToString(), position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ public partial class AnsiConsoleTests
|
|||||||
[InlineData("[yellow]Hello[/", "Encountered malformed markup tag at position 15.")]
|
[InlineData("[yellow]Hello[/", "Encountered malformed markup tag at position 15.")]
|
||||||
[InlineData("[yellow]Hello[/foo", "Encountered malformed markup tag at position 15.")]
|
[InlineData("[yellow]Hello[/foo", "Encountered malformed markup tag at position 15.")]
|
||||||
[InlineData("[yellow Hello", "Encountered malformed markup tag at position 13.")]
|
[InlineData("[yellow Hello", "Encountered malformed markup tag at position 13.")]
|
||||||
|
[InlineData("[yellow[green]]Hello", "Encountered malformed markup tag at position 7.")]
|
||||||
public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
|
public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
|
Loading…
x
Reference in New Issue
Block a user