Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.64 KB

ASP006.md

File metadata and controls

65 lines (50 loc) · 1.64 KB

ASP006

Escape constraint regex

Topic Value
Id ASP006
Severity Warning
Enabled True
Category AspNetCoreAnalyzers.Routing
Code AttributeAnalyzer

Description

Escape constraint regex.

Motivation

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);
}

How to fix violations

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 severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#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

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing", 
    "ASP006:Escape constraint regex", 
    Justification = "Reason...")]