Topic | Value |
---|---|
Id | ASP006 |
Severity | Warning |
Enabled | True |
Category | AspNetCoreAnalyzers.Routing |
Code | AttributeAnalyzer |
Escape constraint regex.
Regular expressions used as parameter constraints must be escaped, see docs.
[HttpGet("api/orders/{id.regex(^\d{3}-\d{2}-\d{4}$)}")]
public IActionResult GetId(string id)
{
return this.Ok(id);
}
Use the code fix to escape the code above.
[HttpGet("api/orders/{id.regex(^\\d{{3}}-\\d{{2}}-\\d{{4}}$)}")]
public IActionResult GetId(string id)
{
return this.Ok(id);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable ASP006 // Escape constraint regex
Code violating the rule here
#pragma warning restore ASP006 // Escape constraint regex
Or put this at the top of the file to disable all instances.
#pragma warning disable ASP006 // Escape constraint regex
[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing",
"ASP006:Escape constraint regex",
Justification = "Reason...")]