From e400e9f335ff7fda58f7739dedeb041de0b477e1 Mon Sep 17 00:00:00 2001 From: Jeremy Sinclair <4016293+snickler@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:52:14 -0400 Subject: [PATCH] [PTRun][Calculator] Fix CA1874 warning in CalculateEngine --- .../CalculateEngine.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs index ef7e84fbd8..f44a72676c 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs @@ -11,7 +11,7 @@ using Mages.Core; namespace Microsoft.PowerToys.Run.Plugin.Calculator { - public class CalculateEngine + public partial class CalculateEngine { private readonly Engine _magesEngine = new Engine(new Configuration { @@ -45,7 +45,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator // check for division by zero // We check if the string contains a slash followed by space (optional) and zero. Whereas the zero must not be followed by a dot, comma, 'b', 'o' or 'x' as these indicate a number with decimal digits or a binary/octal/hexadecimal value respectively. The zero must also not be followed by other digits. - if (new Regex("\\/\\s*0(?!(?:[,\\.0-9]|[box]0*[1-9a-f]))", RegexOptions.IgnoreCase).Match(input).Success) + if (DivisionByZeroRegex().IsMatch(input)) { error = Properties.Resources.wox_plugin_calculator_division_by_zero; return default; @@ -124,5 +124,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator return result; } + + [GeneratedRegex("\\/\\s*0(?!(?:[,\\.0-9]|[box]0*[1-9a-f]))", RegexOptions.IgnoreCase, "en-US")] + private static partial Regex DivisionByZeroRegex(); } }