Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S6931 FN: Route starting with ~ character #9409

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void ReportIssues(SonarSymbolReportingContext context, INamedTypeSymbol
// 1. The controller does not have any actions defined
// 2. At least one action is not annotated with a route attribute or is annotated with a parameterless attribute
// 3. There is at least one action with a route template that does not start with '/'
if (!actions.Any() || actions.Any(x => !x.RouteParameters.Any() || x.RouteParameters.Values.Any(x => !x.StartsWith("/"))))
if (!actions.Any() || actions.Any(x => !x.RouteParameters.Any() || x.RouteParameters.Values.Any(x => !x.StartsWith("/") && !x.StartsWith("~/"))))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,10 @@ public partial class PartialCompliantController : Controller // Compliant - its
[Route("/[action]")]
public ActionResult Index3() => View();
}

// https://github.com/SonarSource/sonar-dotnet/issues/9002
public class Repro_9002 : Controller // Noncompliant
{
[Route("~/B")] // Secondary
public ActionResult Index() => View();
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,10 @@ public partial class CompliantPartialAutogeneratedController : Controller // Com
[Route("/SubPath/Index2")]
public IActionResult Index2() => View();
}

// https://github.com/SonarSource/sonar-dotnet/issues/9002
public class Repro_9002 : Controller // Noncompliant
{
[Route("~/B")] // Secondary
public IActionResult Index() => View();
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,13 @@ Public Class ControllerRequirementsInfluenceActionsCheck
End Class

End Class

' https://github.com/SonarSource/sonar-dotnet/issues/9002
Public Class Repro_9002 ' Noncompliant
Inherits Controller

<Route("~/B")> ' Secondary
Public Function Index() As ActionResult
Return View()
End Function
End Class