From 03cf5c5745e9e36aa0c199bddd2e57dec595e5d5 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Thu, 23 Jun 2022 04:20:22 +0700 Subject: [PATCH] Fix some errors formatted text not being reported Formatted blocks with empty contents were not being reported sometimes when formatted text ended with them, e.g. "{$red$red}". --- .../FormattedStrings/FormattingCommandsSequence.uc | 5 +++-- sources/Text/Tests/TEST_FormattedStrings.uc | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sources/Text/FormattedStrings/FormattingCommandsSequence.uc b/sources/Text/FormattedStrings/FormattingCommandsSequence.uc index 6d2a23e..e269e63 100644 --- a/sources/Text/FormattedStrings/FormattingCommandsSequence.uc +++ b/sources/Text/FormattedStrings/FormattingCommandsSequence.uc @@ -244,8 +244,9 @@ private final function BuildSelf() currentContents[currentContents.length] = nextCharacter; characterCounter += 1; } - // Only put in empty command if there is nothing else - if (currentContents.length > 0 || commandSequence.length == 0) + // Only put in empty command if it is push command or there is nothing else + if ( currentCommand.type == FST_StackPush + || currentContents.length > 0 || commandSequence.length == 0) { currentCommand.contents = currentContents; commandSequence[commandSequence.length] = currentCommand; diff --git a/sources/Text/Tests/TEST_FormattedStrings.uc b/sources/Text/Tests/TEST_FormattedStrings.uc index 4b3569e..bfd69f4 100644 --- a/sources/Text/Tests/TEST_FormattedStrings.uc +++ b/sources/Text/Tests/TEST_FormattedStrings.uc @@ -373,6 +373,7 @@ protected static function Test_Errors() SubTest_ErrorBadColor(); SubTest_ErrorBadShortColorTag(); SubTest_ErrorBadGradientPoint(); + SubTest_ErrorBadGradientPointEmptyBlock(); SubTest_AllErrors(); } @@ -511,6 +512,18 @@ protected static function SubTest_ErrorBadGradientPoint() TEST_ExpectTrue(errors[2].cause.ToString() == "3c"); } +protected static function SubTest_ErrorBadGradientPointEmptyBlock() +{ + local array errors; + Issue("Bad gradient point with empty text block is not reported."); + errors = class'FormattingStringParser'.static.ParseFormatted( + P("{$red$red}"),, true); + TEST_ExpectTrue(errors.length == 1); + TEST_ExpectTrue(errors[0].type == FSE_BadGradientPoint); + TEST_ExpectTrue(errors[0].cause.ToString() == "$red}"); + TEST_ExpectTrue(errors[0].count == 0); +} + protected static function SubTest_AllErrors() { local int i;