From 3dd72b84ee1acb313ff3a9f8ef6ff0da08a8754a Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Tue, 25 Feb 2020 22:16:07 +0300 Subject: [PATCH] Fix throws exception by \color --- src/WpfMath.Tests/ParserExceptionTests.fs | 5 +++++ src/WpfMath/TexFormulaParser.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/WpfMath.Tests/ParserExceptionTests.fs b/src/WpfMath.Tests/ParserExceptionTests.fs index 8a34f699..7540852f 100644 --- a/src/WpfMath.Tests/ParserExceptionTests.fs +++ b/src/WpfMath.Tests/ParserExceptionTests.fs @@ -52,6 +52,11 @@ let ``"\binom{}" should throw a TexParseException``(): unit = let ex = assertParseThrows @"\binom{}" Assert.Equal("An element is missing", ex.Message) +[] +let ``"\color" should throw a TexParseException``(): unit = + let ex = assertParseThrows @"\color" + Assert.Equal("An element is missing", ex.Message) + [] let ``"\color{red}" should throw a TexParseException``(): unit = let ex = assertParseThrows @"\color{red}" diff --git a/src/WpfMath/TexFormulaParser.cs b/src/WpfMath/TexFormulaParser.cs index 0611813a..9679a987 100644 --- a/src/WpfMath/TexFormulaParser.cs +++ b/src/WpfMath/TexFormulaParser.cs @@ -349,7 +349,7 @@ private static SourceSpan ReadElementGroupOptional( char closeChar) { SkipWhiteSpace(value, ref position); - if (value[position] != openChar) + if (position == value.Length || value[position] != openChar) return null; return ReadElementGroup(value, ref position, openChar, closeChar);