Repository: microsoft/PowerToys
File: src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs (C#)

Code before:
    {
        private readonly Engine _magesEngine = new Engine(new Configuration
        {
            Scope = new Dictionary<string, object>
            {
                { "e", Math.E }, // e is not contained in the default mages engine
            },
        });

        public const int RoundingDigits = 10;

        /// <summary>
        /// Interpret
        /// </summary>
        /// <param name="cultureInfo">Use CultureInfo.CurrentCulture if something is user facing</param>
        public CalculateResult Interpret(string input, CultureInfo cultureInfo, out string error)
        {
            error = default;

            if (!CalculateHelper.InputValid(input))
            {
                return default;
            }

            // check for division by zero
            if (input.Contains("/0") || input.Contains("/ 0"))
            {
                error = Properties.Resources.wox_plugin_calculator_division_by_zero;
                return default;
            }

            // mages has quirky log representation
            // mage has log == ln vs log10
            input = input.
                        Replace("log(", "log10(", true, CultureInfo.CurrentCulture).
                        Replace("ln(", "log(", true, CultureInfo.CurrentCulture);

            var result = _magesEngine.Interpret(input);

            // This could happen for some incorrect queries, like pi(2)
            if (result == null)
            {
                error = Properties.Resources.wox_plugin_calculator_expression_not_complete;
                return default;
            }

            result = TransformResult(result);
            if (result is string)
            {
                error = result as string;
                return default;

Review comment (suggestion):
Replace with regexp `\/\s*0(?![,\.])` to not block division by number with decimal digits and add test case. Explain regexp in comment.

```
regexp results:
/0 => true
/ 0 => true
/0 . => true
/0 , => true
/0, => false
/0. => false
```

Code after:
    public class CalculateEngine
    {
        private readonly Engine _magesEngine = new Engine(new Configuration
        {
            Scope = new Dictionary<string, object>
            {
                { "e", Math.E }, // e is not contained in the default mages engine
            },
        });

        public const int RoundingDigits = 10;

        /// <summary>
        /// Interpret
        /// </summary>
        /// <param name="cultureInfo">Use CultureInfo.CurrentCulture if something is user facing</param>
        public CalculateResult Interpret(string input, CultureInfo cultureInfo, out string error)
        {
            error = default;

            if (!CalculateHelper.InputValid(input))
            {
                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.
                        Replace("log(", "log10(", true, CultureInfo.CurrentCulture).
                        Replace("ln(", "log(", true, CultureInfo.CurrentCulture);

            var result = _magesEngine.Interpret(input);

            // This could happen for some incorrect queries, like pi(2)
            if (result == null)
            {
                error = Properties.Resources.wox_plugin_calculator_expression_not_complete;
                return default;
            }

            result = TransformResult(result);
            if (result is string)
            {