Skip to content

[Bug]: CLI crashes parsing macOS .gitignore with RegexParseException #1886

Description

@owenfarrell

Description

CSharpier 1.3.0 crashes when parsing a .gitignore file containing certain glob patterns from the standard GitHub macOS .gitignore template. The CLI throws an unhandled RegexParseException during ignore rule compilation, preventing the formatter from running.

Steps to Reproduce

  1. Create or update a .gitignore file with patterns from the latest GitHub macOS .gitignore template (https://github.com/github/gitignore/blob/main/Global/macOS.gitignore)
  2. Run dotnet csharpier format . (or csharpier format .)

Expected Behavior

CSharpier should either:

  • Successfully parse the .gitignore file and ignore the specified patterns, OR
  • Emit a clear, actionable error message indicating which pattern is invalid and needs to be fixed

Actual Behavior

The formatter crashes with an unhandled exception:

Unhandled exception: System.Text.RegularExpressions.RegexParseException: Invalid pattern '^Icon(?!/)[$' at offset 12. Unterminated [] set.
   at System.Text.RegularExpressions.RegexParser.ScanCharClass(Boolean caseInsensitive, Boolean scanOnly)
   at System.Text.RegularExpressions.RegexParser.CountCaptures(RegexOptions& optionsFoundInPattern)
   at System.Text.RegularExpressions.RegexParser.Parse(String pattern, RegexOptions options, CultureInfo culture)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo culture)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions