codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.88k stars 352 forks source link

TryDefault regex parsing exception #1051

Open asdfchlwnsgy1236 opened 3 months ago

asdfchlwnsgy1236 commented 3 months ago

Environment

Description

Using the Cleanup Active Document command aborts with the following exception:

[CodeMaid Handled Exception 11:53:30 PM] TryDefault caught an exception on 'System.Func`1[System.Boolean]': System.ArgumentException: parsing "\.operator ++" - Nested quantifier +.
   at System.Text.RegularExpressions.RegexParser.ScanRegex()
   at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)
   at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
   at SteveCadwallader.CodeMaid.Model.CodeItems.BaseCodeItemElement.TryDefault[T](Func`1 func) in C:\projects\codemaid\CodeMaidShared\Model\CodeItems\BaseCodeItemElement.cs:line 139

Steps to recreate

  1. Make a file with the following code:

    namespace CodeMaidTest {
    public struct CustomNumber {
        public double a, b;
    
        /// <summary>
        ///   testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing
        /// </summary>
        public CustomNumber(double a, double b) {
            this.a = a;
            this.b = b;
        }
    
        public static CustomNumber operator ++(CustomNumber n) => new CustomNumber(n.a + 1, n.b + 1);
    }
    }
  2. Go to the CodeMaid options -> Formatting -> Set the Wrap comments at column option small enough to make the comment in the code require wrapping, and enable the Run format comments during cleanup option.
  3. Run the Cleanup Active Document command.
  4. Check the output window.

Current behavior

It currently raises a regex parsing exception on the increment method overload and stops. Note that this happens consistently if there is a comment that requires wrapping anywhere in the file. Otherwise when there are no comments or only short comments, only the first time the command is run triggers the exception.

Expected behavior

It should handle this without any exceptions and finish cleanup as normal.