From 949057b1c3bfb1d975684e435da5823c4c18e5d6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 30 May 2024 17:22:43 +0200 Subject: [PATCH] Fix some html tags parsing to be safer --- Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs index a085fb25f..6c5240977 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs @@ -48,8 +48,8 @@ namespace FlaxEngine.GUI { if (alphaText.Length == 3 && alphaText[0] == '#') style.Color.A = ((StringUtils.HexDigit(alphaText[1]) << 4) + StringUtils.HexDigit(alphaText[2])) / 255.0f; - else if (alphaText.Length > 1 && alphaText[alphaText.Length - 1] == '%') - style.Color.A = float.Parse(alphaText.Substring(0, alphaText.Length - 1)) / 100.0f; + else if (alphaText.Length > 1 && alphaText[alphaText.Length - 1] == '%' && float.TryParse(alphaText.Substring(0, alphaText.Length - 1), out var alpha)) + style.Color.A = alpha / 100.0f; } context.StyleStack.Push(style); } @@ -297,8 +297,8 @@ namespace FlaxEngine.GUI { if (float.TryParse(text, out var width)) output = width; - if (text.Length > 1 && text[text.Length - 1] == '%') - output = input * float.Parse(text.Substring(0, text.Length - 1)) / 100.0f; + if (text.Length > 1 && text[text.Length - 1] == '%' && float.TryParse(text.Substring(0, text.Length - 1), out width)) + output = input * width / 100.0f; used = true; } return used;