Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryDefault regex parsing exception #1051

Open
asdfchlwnsgy1236 opened this issue Apr 10, 2024 · 0 comments
Open

TryDefault regex parsing exception #1051

asdfchlwnsgy1236 opened this issue Apr 10, 2024 · 0 comments

Comments

@asdfchlwnsgy1236
Copy link

asdfchlwnsgy1236 commented Apr 10, 2024

Environment

  • Visual Studio version: 2022 Community (17.9.6)
  • CodeMaid version: 12.0
  • Code language: C#

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);
	}
}
  1. 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.
  2. Run the Cleanup Active Document command.
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant