[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

@@ -38,9 +38,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return false;
}
// If the input ends with a binary operator then it is not a valid input to mages and the Interpret function would throw an exception.
// If the input ends with a binary operator then it is not a valid input to mages and the Interpret function would throw an exception. Because we expect here that the user has not finished typing we block those inputs.
string trimmedInput = input.TrimEnd();
if (trimmedInput.EndsWith('+') || trimmedInput.EndsWith('-') || trimmedInput.EndsWith('*') || trimmedInput.EndsWith('|') || trimmedInput.EndsWith('\\') || trimmedInput.EndsWith('^') || trimmedInput.EndsWith('=') || trimmedInput.EndsWith('&'))
if (trimmedInput.EndsWith('+') || trimmedInput.EndsWith('-') || trimmedInput.EndsWith('*') || trimmedInput.EndsWith('|') || trimmedInput.EndsWith('\\') || trimmedInput.EndsWith('^') || trimmedInput.EndsWith('=') || trimmedInput.EndsWith('&') || trimmedInput.EndsWith('/') || trimmedInput.EndsWith('%'))
{
return false;
}