From 761713601787c0a5e6539303e2b7b388a792ccee Mon Sep 17 00:00:00 2001 From: Connor Plante Date: Fri, 13 Dec 2024 16:46:23 -0500 Subject: [PATCH 1/2] add '0x' handling for divide by 0 scenarios --- .../CalculateEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 912b1dc1b19c..b3e926e7f1a8 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 @@ -38,7 +38,7 @@ public CalculateResult Interpret(string input, CultureInfo cultureInfo, out stri // 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) + if (new Regex("\\/\\s*0(?![,\\.0-9xX])").Match(input).Success) { error = Properties.Resources.wox_plugin_calculator_division_by_zero; return default; From 981608b6eaf8b4c5f577d628ffa33021eec0ef19 Mon Sep 17 00:00:00 2001 From: Connor Plante Date: Wed, 18 Dec 2024 09:03:31 -0500 Subject: [PATCH 2/2] fix comment on division by 0 check --- .../CalculateEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b3e926e7f1a8..3aef7ba25486 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,7 +37,7 @@ public CalculateResult Interpret(string input, CultureInfo cultureInfo, out stri } // 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. + // 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;