From 2ba5fb75bc8bd9c374b07be2bc65eb01b38a4e76 Mon Sep 17 00:00:00 2001 From: Connor Plante <150482134+plante-msft@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:48:17 -0500 Subject: [PATCH] [PTRun][Calculator]Handle hexadecimal numbers to not return divide by 0 error (#36390) * add '0x' handling for divide by 0 scenarios * fix comment on division by 0 check --------- Co-authored-by: Connor Plante --- .../CalculateEngine.cs | 4 ++-- 1 file changed, 2 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 912b1dc1b1..3aef7ba254 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 @@ -37,8 +37,8 @@ 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 followed by dot or comma as this indicates a number with decimal digits. The zero must also not be followed by other digits. - if (new Regex("\\/\\s*0(?![,\\.0-9])").Match(input).Success) + // 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, or 'x'/'X' as these indicate a number with decimal digits or a hexadecimal value respectively. The zero must also not be followed by other digits. + if (new Regex("\\/\\s*0(?![,\\.0-9xX])").Match(input).Success) { error = Properties.Resources.wox_plugin_calculator_division_by_zero; return default;