Skip to content

Convert to generated regex fixer is disabled on regex parse errors hit during counting captures #80004

@danmoseley

Description

@danmoseley
    private static Regex regex = new Regex(@"abc\g");

Run the fixer, it gets disabled with a banner, clicking on 'show stack' gives the below

System.Text.RegularExpressions.RegexParseException : Invalid pattern '\g' at offset 2. Unrecognized escape sequence \\g.
   at System.Text.RegularExpressions.RegexParser.ScanCharEscape()
   at System.Text.RegularExpressions.RegexParser.ScanBasicBackslash(Boolean scanOnly)
   at System.Text.RegularExpressions.RegexParser.ScanBackslash(Boolean scanOnly)
   at System.Text.RegularExpressions.RegexParser.CountCaptures(RegexOptions& optionsFoundInPattern)
   at System.Text.RegularExpressions.RegexParser.ParseOptionsInPattern(String pattern,RegexOptions options)
   at async System.Text.RegularExpressions.Generator.UpgradeToGeneratedRegexCodeFixer.ConvertToSourceGenerator(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Parse errors that the capture-counting path skips do not hit this, eg.,

private static Regex regex = new Regex(@".{23423423434324243}");

This will offer the fixer and run it. (Possibly it should not offer the fixer, but at least it doesn't crash.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions