[PT Run][Calculator] Input validation improvements (#20067)

* improve input validation

* update test

* update tests

* simplify test case

* fix devision by zero check
This commit is contained in:
Heiko
2022-08-26 17:40:15 +02:00
committed by GitHub
parent eedea3159c
commit 785160653c
6 changed files with 85 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using Mages.Core;
namespace Microsoft.PowerToys.Run.Plugin.Calculator
@@ -34,6 +35,14 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return default;
}
// 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.
if (new Regex("\\/\\s*0(?![,\\.])").Match(input).Success)
{
error = Properties.Resources.wox_plugin_calculator_division_by_zero;
return default;
}
// mages has quirky log representation
// mage has log == ln vs log10
input = input.