dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.63k stars 4.57k forks source link

SYSLIB1045 Quick fix generates badly formed string #104371

Open vsfeedback opened 2 weeks ago

vsfeedback commented 2 weeks ago

This issue has been moved from a ticket on Developer Community.


Create the following class:

public static class Foo
{
    public static readonly Regex IllegalCharactersRegex = new("[" + @"\/:<>|" + "\"]", RegexOptions.Compiled);
}

The quick fix suggest to convert the regex to 'GeneratedRegexAttribute'.

If you do, it generates the following code :

public static partial class Foo
{
    public static readonly Regex IllegalCharactersRegex = MyRegex();

[GeneratedRegex(@"[\/:<>|"]", RegexOptions.Compiled)]
    private static partial Regex MyRegex();
}

But the string is badly formed. It should be @"[\/:<>|""]" instead.


Original Comments

Feedback Bot on 6/16/2024, 11:03 PM:

(private comment, text removed)


Original Solutions

(no solutions)

dotnet-policy-service[bot] commented 2 weeks ago

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions See info in area-owners.md if you want to be subscribed.